From 668a9245f31c00628f8e18a1f3a35946acd1d132 Mon Sep 17 00:00:00 2001 From: rouzwelt Date: Wed, 25 Dec 2024 23:31:56 +0000 Subject: [PATCH 1/6] init --- README.md | 8 ++++---- example.env | 4 ++-- src/cli.ts | 18 ++++++------------ src/modes/interOrderbook.ts | 3 --- src/modes/intraOrderbook.ts | 3 --- src/modes/routeProcessor.ts | 3 --- src/tx.ts | 20 +++++++++++++++++--- src/types.ts | 4 ++-- test/cli.test.js | 4 ++-- test/tx.test.ts | 20 ++++++++++++++++++++ 10 files changed, 53 insertions(+), 34 deletions(-) diff --git a/README.md b/README.md index ef29e2b1..4e0df47c 100644 --- a/README.md +++ b/README.md @@ -113,8 +113,8 @@ Other optional arguments are: - `--owner-profile`, Specifies the owner limit, example: --owner-profile 0x123456=12 . Will override the 'OWNER_PROFILE' in env variables - `--public-rpc`, Allows to use public RPCs as fallbacks, default is false. Will override the 'PUBLIC_RPC' in env variables - `--gas-price-multiplier`, Option to multiply the gas price fetched from the rpc as percentage, default is 107, ie +7%. Will override the 'GAS_PRICE_MULTIPLIER' in env variables -- `--gas-limit-multiplier`, Option to multiply the gas limit estimation from the rpc as percentage, default is 108, ie +8%. Will override the 'GAS_LIMIT_MULTIPLIER' in env variables -- `--tx-gas`, Option to set a static gas limit for all submitting txs. Will override the 'TX_GAS' in env variables +- `--gas-limit-multiplier`, Option to multiply the gas limit estimation from the rpc as percentage, default is 105, ie +5%. Will override the 'GAS_LIMIT_MULTIPLIER' in env variables +- `--tx-gas`, Option to set a gas limit for all submitting txs optionally with appended percentage sign to apply as percentage to original gas. Will override the 'TX_GAS' in env variables - `--rp-only`, Only clear orders through RP4, excludes intra and inter orderbook clears. Will override the 'RP_ONLY' in env variablesin env variables - `-V` or `--version`, output the version number - `-h` or `--help`, output usage information @@ -263,10 +263,10 @@ ROUTE="single" # Option to multiply the gas price fetched from the rpc as percentage, default is 107, ie +7% GAS_PRICE_MULTIPLIER= -# Option to multiply the gas limit estimation from the rpc as percentage, default is 108, ie +8% +# Option to multiply the gas limit estimation from the rpc as percentage, default is 105, ie +5% GAS_LIMIT_MULTIPLIER= -# Option to set a static gas limit for all submitting txs +# Option to set a gas limit for all submitting txs optionally with appended percentage sign to apply as percentage to original gas TX_GAS= # Only clear orders through RP4, excludes intra and inter orderbook clears diff --git a/example.env b/example.env index 25e38948..3639d4cb 100644 --- a/example.env +++ b/example.env @@ -88,10 +88,10 @@ ROUTE="single" # Option to multiply the gas price fetched from the rpc as percentage, default is 107, ie +7% GAS_PRICE_MULTIPLIER= -# Option to multiply the gas limit estimation from the rpc as percentage, default is 108, ie +8% +# Option to multiply the gas limit estimation from the rpc as percentage, default is 105, ie +5% GAS_LIMIT_MULTIPLIER= -# Option to set a static gas limit for all submitting txs +# Option to set a gas limit for all submitting txs optionally with appended percentage sign to apply as percentage to original gas TX_GAS= # Only clear orders through RP4, excludes intra and inter orderbook clears diff --git a/src/cli.ts b/src/cli.ts index 8e6b5b67..a39bd659 100755 --- a/src/cli.ts +++ b/src/cli.ts @@ -195,11 +195,11 @@ const getOptions = async (argv: any, version?: string) => { ) .option( "--gas-limit-multiplier ", - "Option to multiply the gas limit estimation from the rpc as percentage, default is 108, ie +8%. Will override the 'GAS_LIMIT_MULTIPLIER' in env variables", + "Option to multiply the gas limit estimation from the rpc as percentage, default is 105, ie +5%. Will override the 'GAS_LIMIT_MULTIPLIER' in env variables", ) .option( "--tx-gas ", - "Option to set a static gas limit for all submitting txs. Will override the 'TX_GAS' in env variables", + "Option to set a gas limit for all submitting txs optionally with appended percentage sign to apply as percentage to original gas. Will override the 'TX_GAS' in env variables", ) .option( "--rp-only", @@ -452,18 +452,12 @@ export async function startup(argv: any, version?: string, tracer?: Tracer, ctx? throw "invalid gasLimitMultiplier value, must be an integer greater than zero"; } else throw "invalid gasLimitMultiplier value, must be an integer greater than zero"; } else { - options.gasLimitMultiplier = 108; + options.gasLimitMultiplier = 105; } if (options.txGas) { - if (typeof options.txGas === "number") { - if (options.txGas <= 0 || !Number.isInteger(options.txGas)) - throw "invalid txGas value, must be an integer greater than zero"; - else options.txGas = BigInt(options.txGas); - } else if (typeof options.txGas === "string" && /^[0-9]+$/.test(options.txGas)) { - options.txGas = BigInt(options.txGas); - if (options.txGas <= 0n) - throw "invalid txGas value, must be an integer greater than zero"; - } else throw "invalid txGas value, must be an integer greater than zero"; + if (typeof options.txGas !== "string" || !/^[0-9]+%?$/.test(options.txGas)) { + throw "invalid txGas value, must be an integer greater than zero optionally with appended percentage sign to apply as percentage to original gas"; + } } const poolUpdateInterval = _poolUpdateInterval * 60 * 1000; let ordersDetails: SgOrder[] = []; diff --git a/src/modes/interOrderbook.ts b/src/modes/interOrderbook.ts index fa1763d6..4cae6a25 100644 --- a/src/modes/interOrderbook.ts +++ b/src/modes/interOrderbook.ts @@ -195,9 +195,6 @@ export async function dryrun({ } } rawtx.gas = gasLimit.toBigInt(); - if (typeof config.txGas === "bigint") { - rawtx.gas = config.txGas; - } // if reached here, it means there was a success and found opp spanAttributes["oppBlockNumber"] = blockNumber; diff --git a/src/modes/intraOrderbook.ts b/src/modes/intraOrderbook.ts index 9f69724a..f975754a 100644 --- a/src/modes/intraOrderbook.ts +++ b/src/modes/intraOrderbook.ts @@ -211,9 +211,6 @@ export async function dryrun({ } } rawtx.gas = gasLimit.toBigInt(); - if (typeof config.txGas === "bigint") { - rawtx.gas = config.txGas; - } // if reached here, it means there was a success and found opp spanAttributes["oppBlockNumber"] = blockNumber; diff --git a/src/modes/routeProcessor.ts b/src/modes/routeProcessor.ts index de93eb3d..01750fce 100644 --- a/src/modes/routeProcessor.ts +++ b/src/modes/routeProcessor.ts @@ -273,9 +273,6 @@ export async function dryrun({ } } rawtx.gas = gasLimit.toBigInt(); - if (typeof config.txGas === "bigint") { - rawtx.gas = config.txGas; - } // if reached here, it means there was a success and found opp // rest of span attr are not needed since they are present in the result.data diff --git a/src/tx.ts b/src/tx.ts index af73f053..b6cbcc20 100644 --- a/src/tx.ts +++ b/src/tx.ts @@ -40,9 +40,7 @@ export async function handleTransaction( let txhash: `0x${string}`, txUrl: string; let time = 0; const sendTx = async () => { - if (writeSigner !== undefined) { - rawtx.gas = undefined; - } + rawtx.gas = getTxGas(config, rawtx.gas!); txhash = writeSigner !== undefined ? await writeSigner.sendTx({ @@ -388,3 +386,19 @@ export async function pollSigners(accounts: ViemClient[]): Promise { } } } + +/** + * Returns the gas limit for a tx by applying the specified config + */ +export function getTxGas(config: BotConfig, gas: bigint): bigint { + if (config.txGas) { + if (config.txGas.endsWith("%")) { + const multiplier = BigInt(config.txGas.substring(0, config.txGas.length - 1)); + return (gas * multiplier) / 100n; + } else { + return BigInt(config.txGas); + } + } else { + return gas; + } +} diff --git a/src/types.ts b/src/types.ts index 4284019e..29643104 100644 --- a/src/types.ts +++ b/src/types.ts @@ -50,7 +50,7 @@ export type CliOptions = { route?: string; gasPriceMultiplier: number; gasLimitMultiplier: number; - txGas?: bigint; + txGas?: string; rpOnly?: boolean; }; @@ -190,7 +190,7 @@ export type BotConfig = { rpcRecords: Record; gasPriceMultiplier: number; gasLimitMultiplier: number; - txGas?: bigint; + txGas?: string; rpOnly?: boolean; onFetchRequest?: (request: Request) => void; onFetchResponse?: (request: Response) => void; diff --git a/test/cli.test.js b/test/cli.test.js index 4d4ed3fd..5055cff8 100644 --- a/test/cli.test.js +++ b/test/cli.test.js @@ -210,14 +210,14 @@ describe("Test cli", async function () { }, gasPriceMultiplier: 120, gasLimitMultiplier: 110, - txGas: 123456789n, + txGas: "123456789", rpOnly: true, }, options: { botMinBalance: "0.123", gasPriceMultiplier: 120, gasLimitMultiplier: 110, - txGas: 123456789n, + txGas: "123456789", rpOnly: true, }, }; diff --git a/test/tx.test.ts b/test/tx.test.ts index 1432e166..38ba41d6 100644 --- a/test/tx.test.ts +++ b/test/tx.test.ts @@ -10,6 +10,7 @@ import { handleReceipt, sendTransaction, handleTransaction, + getTxGas, } from "../src/tx"; describe("Test tx", async function () { @@ -415,4 +416,23 @@ describe("Test tx", async function () { const result = await pollSigners(someMockedSigners); assert.equal(result, someMockedSigners[2]); }); + + it("should test getTxGas", async function () { + const gas = 500n; + const config = { + txGas: "120%", + } as any; + let result = getTxGas(config, gas); + let expected = 600n; + assert.equal(result, expected); + + config.txGas = "900"; + result = getTxGas(config, gas); + expected = 900n; + assert.equal(result, expected); + + config.txGas = undefined; + result = getTxGas(config, gas); + assert.equal(result, gas); + }); }); From 227eb0f7e97a9b65a5d583e64718f094bed07d61 Mon Sep 17 00:00:00 2001 From: rouzwelt Date: Wed, 25 Dec 2024 23:35:46 +0000 Subject: [PATCH 2/6] update --- README.md | 4 ++-- example.env | 2 +- src/cli.ts | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 4e0df47c..7dda91c9 100644 --- a/README.md +++ b/README.md @@ -113,7 +113,7 @@ Other optional arguments are: - `--owner-profile`, Specifies the owner limit, example: --owner-profile 0x123456=12 . Will override the 'OWNER_PROFILE' in env variables - `--public-rpc`, Allows to use public RPCs as fallbacks, default is false. Will override the 'PUBLIC_RPC' in env variables - `--gas-price-multiplier`, Option to multiply the gas price fetched from the rpc as percentage, default is 107, ie +7%. Will override the 'GAS_PRICE_MULTIPLIER' in env variables -- `--gas-limit-multiplier`, Option to multiply the gas limit estimation from the rpc as percentage, default is 105, ie +5%. Will override the 'GAS_LIMIT_MULTIPLIER' in env variables +- `--gas-limit-multiplier`, Option to multiply the gas limit estimation from the rpc as percentage, default is 100, ie no change. Will override the 'GAS_LIMIT_MULTIPLIER' in env variables - `--tx-gas`, Option to set a gas limit for all submitting txs optionally with appended percentage sign to apply as percentage to original gas. Will override the 'TX_GAS' in env variables - `--rp-only`, Only clear orders through RP4, excludes intra and inter orderbook clears. Will override the 'RP_ONLY' in env variablesin env variables - `-V` or `--version`, output the version number @@ -263,7 +263,7 @@ ROUTE="single" # Option to multiply the gas price fetched from the rpc as percentage, default is 107, ie +7% GAS_PRICE_MULTIPLIER= -# Option to multiply the gas limit estimation from the rpc as percentage, default is 105, ie +5% +# Option to multiply the gas limit estimation from the rpc as percentage, default is 100, ie no change GAS_LIMIT_MULTIPLIER= # Option to set a gas limit for all submitting txs optionally with appended percentage sign to apply as percentage to original gas diff --git a/example.env b/example.env index 3639d4cb..6a133bc9 100644 --- a/example.env +++ b/example.env @@ -88,7 +88,7 @@ ROUTE="single" # Option to multiply the gas price fetched from the rpc as percentage, default is 107, ie +7% GAS_PRICE_MULTIPLIER= -# Option to multiply the gas limit estimation from the rpc as percentage, default is 105, ie +5% +# Option to multiply the gas limit estimation from the rpc as percentage, default is 100, ie no change GAS_LIMIT_MULTIPLIER= # Option to set a gas limit for all submitting txs optionally with appended percentage sign to apply as percentage to original gas diff --git a/src/cli.ts b/src/cli.ts index a39bd659..b74d3d90 100755 --- a/src/cli.ts +++ b/src/cli.ts @@ -195,7 +195,7 @@ const getOptions = async (argv: any, version?: string) => { ) .option( "--gas-limit-multiplier ", - "Option to multiply the gas limit estimation from the rpc as percentage, default is 105, ie +5%. Will override the 'GAS_LIMIT_MULTIPLIER' in env variables", + "Option to multiply the gas limit estimation from the rpc as percentage, default is 100, ie no change. Will override the 'GAS_LIMIT_MULTIPLIER' in env variables", ) .option( "--tx-gas ", @@ -452,7 +452,7 @@ export async function startup(argv: any, version?: string, tracer?: Tracer, ctx? throw "invalid gasLimitMultiplier value, must be an integer greater than zero"; } else throw "invalid gasLimitMultiplier value, must be an integer greater than zero"; } else { - options.gasLimitMultiplier = 105; + options.gasLimitMultiplier = 100; } if (options.txGas) { if (typeof options.txGas !== "string" || !/^[0-9]+%?$/.test(options.txGas)) { From 7f823010e7a8f0b360e25bd3baa85298e886e2f6 Mon Sep 17 00:00:00 2001 From: rouzwelt Date: Thu, 26 Dec 2024 01:00:39 +0000 Subject: [PATCH 3/6] update --- src/modes/index.ts | 3 ++- test/e2e/e2e.test.js | 9 ++++++--- test/tx.test.ts | 4 ++++ 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/modes/index.ts b/src/modes/index.ts index 80e08cdd..7e52e00f 100644 --- a/src/modes/index.ts +++ b/src/modes/index.ts @@ -44,10 +44,11 @@ export async function findOpp({ fromToken: Token; }): Promise { try { - gasPrice = BigNumber.from(await viemClient.getGasPrice()) + const gp = BigNumber.from(await viemClient.getGasPrice()) .mul(config.gasPriceMultiplier) .div("100") .toBigInt(); + if (gp > gasPrice) gasPrice = gp; } catch { /**/ } diff --git a/test/e2e/e2e.test.js b/test/e2e/e2e.test.js index 3f0a2a73..8b653022 100644 --- a/test/e2e/e2e.test.js +++ b/test/e2e/e2e.test.js @@ -72,6 +72,9 @@ for (let i = 0; i < testData.length; i++) { provider.register(); const tracer = provider.getTracer("arb-bot-tracer"); + config.rpc = [rpc]; + const dataFetcherPromise = getDataFetcher(config, liquidityProviders, false); + // run tests on each rp version for (let j = 0; j < rpVersions.length; j++) { const rpVersion = rpVersions[j]; @@ -79,7 +82,7 @@ for (let i = 0; i < testData.length; i++) { it(`should clear orders successfully using route processor v${rpVersion}`, async function () { config.rpc = [rpc]; const viemClient = await viem.getPublicClient(); - const dataFetcher = await getDataFetcher(config, liquidityProviders, false); + const dataFetcher = await dataFetcherPromise; const testSpan = tracer.startSpan("test-clearing"); const ctx = trace.setSpan(context.active(), testSpan); @@ -342,7 +345,7 @@ for (let i = 0; i < testData.length; i++) { it("should clear orders successfully using inter-orderbook", async function () { config.rpc = [rpc]; const viemClient = await viem.getPublicClient(); - const dataFetcher = await getDataFetcher(config, liquidityProviders, false); + const dataFetcher = await dataFetcherPromise; const testSpan = tracer.startSpan("test-clearing"); const ctx = trace.setSpan(context.active(), testSpan); @@ -693,7 +696,7 @@ for (let i = 0; i < testData.length; i++) { it("should clear orders successfully using intra-orderbook", async function () { config.rpc = [rpc]; const viemClient = await viem.getPublicClient(); - const dataFetcher = await getDataFetcher(config, liquidityProviders, false); + const dataFetcher = await dataFetcherPromise; const testSpan = tracer.startSpan("test-clearing"); const ctx = trace.setSpan(context.active(), testSpan); diff --git a/test/tx.test.ts b/test/tx.test.ts index 38ba41d6..9c4046ab 100644 --- a/test/tx.test.ts +++ b/test/tx.test.ts @@ -419,6 +419,8 @@ describe("Test tx", async function () { it("should test getTxGas", async function () { const gas = 500n; + + // percentage const config = { txGas: "120%", } as any; @@ -426,11 +428,13 @@ describe("Test tx", async function () { let expected = 600n; assert.equal(result, expected); + // static config.txGas = "900"; result = getTxGas(config, gas); expected = 900n; assert.equal(result, expected); + // none config.txGas = undefined; result = getTxGas(config, gas); assert.equal(result, gas); From 0c91fc1810c667cf8c3ae02d0bb023224fe623ee Mon Sep 17 00:00:00 2001 From: rouzwelt Date: Thu, 26 Dec 2024 02:53:11 +0000 Subject: [PATCH 4/6] update --- src/error.ts | 27 +++++++++++++++++++-------- src/modes/routeProcessor.ts | 1 + 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/error.ts b/src/error.ts index e8576204..5d20cf2f 100644 --- a/src/error.ts +++ b/src/error.ts @@ -131,7 +131,8 @@ export function errorSnapshot( * Checks if a viem BaseError is from eth node, copied from * "viem/_types/utils/errors/getNodeError" since not a default export */ -export function containsNodeError(err: BaseError): boolean { +export function containsNodeError(err: BaseError, circuitBreaker = 0): boolean { + if (circuitBreaker > 25) return false; try { const snapshot = errorSnapshot("", err); const parsed = parseRevertError(err); @@ -145,7 +146,7 @@ export function containsNodeError(err: BaseError): boolean { err instanceof InsufficientFundsError || (err instanceof RpcRequestError && err.code === ExecutionRevertedError.code) || (snapshot.includes("exceeds allowance") && !snapshot.includes("out of gas")) || - ("cause" in err && containsNodeError(err.cause as any)) + ("cause" in err && containsNodeError(err.cause as any, ++circuitBreaker)) ); } catch (error) { return false; @@ -155,14 +156,15 @@ export function containsNodeError(err: BaseError): boolean { /** * Checks if a viem BaseError is timeout error */ -export function isTimeout(err: BaseError): boolean { +export function isTimeout(err: BaseError, circuitBreaker = 0): boolean { + if (circuitBreaker > 25) return false; try { return ( err instanceof TimeoutError || err instanceof TransactionNotFoundError || err instanceof TransactionReceiptNotFoundError || err instanceof WaitForTransactionReceiptTimeoutError || - ("cause" in err && isTimeout(err.cause as any)) + ("cause" in err && isTimeout(err.cause as any, ++circuitBreaker)) ); } catch (error) { return false; @@ -227,14 +229,23 @@ export async function handleRevert( /** * Parses a revert error to TxRevertError type */ -export function parseRevertError(error: BaseError): TxRevertError { +export function parseRevertError(error: BaseError, circuitBreaker = 0): TxRevertError { + if (circuitBreaker > 25) { + return { + raw: { + code: -2, + message: + "Couldn't extract rpc error from the viem error object because the viem error object is circular", + }, + }; + } if ("cause" in error) { - return parseRevertError(error.cause as any); + return parseRevertError(error.cause as any, ++circuitBreaker); } else { let decoded: DecodedError | undefined; const raw: RawError = { - code: (error as any).code ?? NaN, - message: error.message, + code: (error as any).code ?? -2, + message: error.message ?? "No error msg", data: (error as any).data ?? undefined, }; if ("data" in error && isHex(error.data)) { diff --git a/src/modes/routeProcessor.ts b/src/modes/routeProcessor.ts index 01750fce..bf2958a0 100644 --- a/src/modes/routeProcessor.ts +++ b/src/modes/routeProcessor.ts @@ -91,6 +91,7 @@ export async function dryrun({ config.route, ); if (route.status == "NoWay") { + if (hasPriceMatch) hasPriceMatch.value = false; spanAttributes["route"] = "no-way"; result.reason = RouteProcessorDryrunHaltReason.NoRoute; return Promise.reject(result); From a9078be548c953150d85818e9d7771e980fbe878 Mon Sep 17 00:00:00 2001 From: rouzwelt Date: Thu, 26 Dec 2024 04:05:03 +0000 Subject: [PATCH 5/6] test --- src/modes/routeProcessor.ts | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/modes/routeProcessor.ts b/src/modes/routeProcessor.ts index bf2958a0..d1bacf56 100644 --- a/src/modes/routeProcessor.ts +++ b/src/modes/routeProcessor.ts @@ -540,6 +540,23 @@ export function findMaxInput({ const result: BigNumber[] = []; const ratio = orderPairObject.takeOrders[0].quote!.ratio; const pcMap = dataFetcher.getCurrentPoolCodeMap(fromToken, toToken); + if ( + fromToken.address.toLowerCase() === + "0xb02541995f317fd47c5df8e8fba7284b502b5d7b".toLowerCase() || + toToken.address.toLowerCase() === "0xb02541995f317fd47c5df8e8fba7284b502b5d7b".toLowerCase() + ) { + pcMap.forEach((x) => { + if ( + x.pool.token0.address.toLowerCase() === + "0xb02541995f317fd47c5df8e8fba7284b502b5d7b".toLowerCase() || + x.pool.token1.address.toLowerCase() === + "0xb02541995f317fd47c5df8e8fba7284b502b5d7b".toLowerCase() + ) { + // eslint-disable-next-line no-console + console.log(x); + } + }); + } const initAmount = scale18To(maximumInputFixed, fromToken.decimals).div(2); let maximumInput = BigNumber.from(initAmount.toString()); for (let i = 1; i < 26; i++) { @@ -558,8 +575,26 @@ export function findMaxInput({ ); if (route.status == "NoWay") { + if ( + fromToken.address.toLowerCase() === + "0xb02541995f317fd47c5df8e8fba7284b502b5d7b".toLowerCase() || + toToken.address.toLowerCase() === + "0xb02541995f317fd47c5df8e8fba7284b502b5d7b".toLowerCase() + ) { + // eslint-disable-next-line no-console + console.log("noway", maximumInput.toString()); + } maximumInput = maximumInput.sub(initAmount.div(2 ** i)); } else { + if ( + fromToken.address.toLowerCase() === + "0xb02541995f317fd47c5df8e8fba7284b502b5d7b".toLowerCase() || + toToken.address.toLowerCase() === + "0xb02541995f317fd47c5df8e8fba7284b502b5d7b".toLowerCase() + ) { + // eslint-disable-next-line no-console + console.log("way", maximumInput.toString()); + } const amountOut = scale18(route.amountOutBI, toToken.decimals); const price = amountOut.mul("1" + "0".repeat(18)).div(maxInput18); From a5de0810b95a2c2f20883de1cd7c8354522eb3cf Mon Sep 17 00:00:00 2001 From: rouzwelt Date: Thu, 26 Dec 2024 04:13:07 +0000 Subject: [PATCH 6/6] Revert "test" This reverts commit a9078be548c953150d85818e9d7771e980fbe878. --- src/modes/routeProcessor.ts | 35 ----------------------------------- 1 file changed, 35 deletions(-) diff --git a/src/modes/routeProcessor.ts b/src/modes/routeProcessor.ts index d1bacf56..bf2958a0 100644 --- a/src/modes/routeProcessor.ts +++ b/src/modes/routeProcessor.ts @@ -540,23 +540,6 @@ export function findMaxInput({ const result: BigNumber[] = []; const ratio = orderPairObject.takeOrders[0].quote!.ratio; const pcMap = dataFetcher.getCurrentPoolCodeMap(fromToken, toToken); - if ( - fromToken.address.toLowerCase() === - "0xb02541995f317fd47c5df8e8fba7284b502b5d7b".toLowerCase() || - toToken.address.toLowerCase() === "0xb02541995f317fd47c5df8e8fba7284b502b5d7b".toLowerCase() - ) { - pcMap.forEach((x) => { - if ( - x.pool.token0.address.toLowerCase() === - "0xb02541995f317fd47c5df8e8fba7284b502b5d7b".toLowerCase() || - x.pool.token1.address.toLowerCase() === - "0xb02541995f317fd47c5df8e8fba7284b502b5d7b".toLowerCase() - ) { - // eslint-disable-next-line no-console - console.log(x); - } - }); - } const initAmount = scale18To(maximumInputFixed, fromToken.decimals).div(2); let maximumInput = BigNumber.from(initAmount.toString()); for (let i = 1; i < 26; i++) { @@ -575,26 +558,8 @@ export function findMaxInput({ ); if (route.status == "NoWay") { - if ( - fromToken.address.toLowerCase() === - "0xb02541995f317fd47c5df8e8fba7284b502b5d7b".toLowerCase() || - toToken.address.toLowerCase() === - "0xb02541995f317fd47c5df8e8fba7284b502b5d7b".toLowerCase() - ) { - // eslint-disable-next-line no-console - console.log("noway", maximumInput.toString()); - } maximumInput = maximumInput.sub(initAmount.div(2 ** i)); } else { - if ( - fromToken.address.toLowerCase() === - "0xb02541995f317fd47c5df8e8fba7284b502b5d7b".toLowerCase() || - toToken.address.toLowerCase() === - "0xb02541995f317fd47c5df8e8fba7284b502b5d7b".toLowerCase() - ) { - // eslint-disable-next-line no-console - console.log("way", maximumInput.toString()); - } const amountOut = scale18(route.amountOutBI, toToken.decimals); const price = amountOut.mul("1" + "0".repeat(18)).div(maxInput18);