diff --git a/lib/sushiswap b/lib/sushiswap index 9792524a..08e5a51f 160000 --- a/lib/sushiswap +++ b/lib/sushiswap @@ -1 +1 @@ -Subproject commit 9792524a444f30c437f7854a44c79db1a47116ad +Subproject commit 08e5a51ff926203b40720947c6471a477f2d04c7 diff --git a/package-lock.json b/package-lock.json index 69d7af5b..30bb441f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14266,7 +14266,6 @@ "hasInstallScript": true, "inBundle": true, "license": "MIT", - "peer": true, "dependencies": { "node-addon-api": "^2.0.0", "node-gyp-build": "^4.2.0" @@ -14896,8 +14895,7 @@ "version": "2.0.2", "dev": true, "inBundle": true, - "license": "MIT", - "peer": true + "license": "MIT" }, "node_modules/ganache-core/node_modules/node-fetch": { "version": "2.1.2", @@ -14913,7 +14911,6 @@ "dev": true, "inBundle": true, "license": "MIT", - "peer": true, "bin": { "node-gyp-build": "bin.js", "node-gyp-build-optional": "optional.js", diff --git a/src/config.ts b/src/config.ts index a60b9cce..057dc799 100644 --- a/src/config.ts +++ b/src/config.ts @@ -2,7 +2,7 @@ import { getSgOrderbooks } from "./sg"; import { sendTransaction } from "./tx"; import { WNATIVE } from "sushi/currency"; import { ChainId, ChainKey } from "sushi/chain"; -import { DataFetcher, LiquidityProviders } from "sushi/router"; +import { RainDataFetcher, LiquidityProviders } from "sushi/router"; import { BotConfig, RpcRecord, @@ -206,7 +206,7 @@ export async function getDataFetcher( useFallbacks = false, ): Promise { try { - const dataFetcher = new DataFetcher( + const dataFetcher = new RainDataFetcher( configOrViemClient.chain!.id as ChainId, "transport" in configOrViemClient ? (configOrViemClient as PublicClient) diff --git a/src/processOrders.ts b/src/processOrders.ts index 8b0223fb..c22524ca 100644 --- a/src/processOrders.ts +++ b/src/processOrders.ts @@ -265,6 +265,14 @@ export const processOrders = async ( } span.setAttribute("severity", ErrorSeverity.MEDIUM); span.setStatus({ code: SpanStatusCode.ERROR, message }); + } else if (e.reason === ProcessPairHaltReason.FailedToUpdatePools) { + let message = pair + ": failed to update pool details by event data"; + if (e.error) { + message = errorSnapshot(message, e.error); + span.recordException(e.error); + } + span.setAttribute("severity", ErrorSeverity.MEDIUM); + span.setStatus({ code: SpanStatusCode.ERROR, message }); } else if (e.reason === ProcessPairHaltReason.FailedToGetEthPrice) { // set OK status because a token might not have a pool and as a result eth price cannot // be fetched for it and if it is set to ERROR it will constantly error on each round @@ -464,6 +472,25 @@ export async function processPair(args: { }); const gasPrice = BigNumber.from(state.gasPrice); + + // update pools by events watching until current block + try { + if (dataFetcher.fetchedPairPools?.length) { + let blockNumber; + if (isE2eTest && (config as any).testBlockNumberTemp) { + (config as any).testBlockNumberTemp += 10n; + blockNumber = (config as any).testBlockNumberTemp; + } + await dataFetcher.updatePools(blockNumber); + } + } catch (e) { + result.reason = ProcessPairHaltReason.FailedToUpdatePools; + result.error = e; + return async () => { + throw result; + }; + } + // get pool details if ( !dataFetcher.fetchedPairPools.includes(pair) || diff --git a/src/types.ts b/src/types.ts index 15130c01..40048f3f 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,7 +1,7 @@ import { BigNumber } from "ethers"; import { Token } from "sushi/currency"; import { AttributeValue } from "@opentelemetry/api"; -import { DataFetcher, LiquidityProviders } from "sushi/router"; +import { RainDataFetcher, LiquidityProviders } from "sushi/router"; import { Chain, Account, @@ -25,7 +25,8 @@ export enum ProcessPairHaltReason { TxFailed = 4, TxMineFailed = 5, TxReverted = 6, - UnexpectedError = 7, + FailedToUpdatePools = 7, + UnexpectedError = 8, } /** @@ -183,7 +184,7 @@ export type TestViemClient = TestClient<"hardhat"> & ) => Promise<`0x${string}`>; }; -export type BotDataFetcher = DataFetcher & { fetchedPairPools: string[] }; +export type BotDataFetcher = RainDataFetcher & { fetchedPairPools: string[] }; export type ChainConfig = { chain: Chain; diff --git a/src/utils.ts b/src/utils.ts index 4d368bc2..a4701f39 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -7,7 +7,7 @@ import { isBytes, isHexString } from "ethers/lib/utils"; import { BigNumber, BigNumberish, ethers } from "ethers"; import { erc20Abi, parseEventLogs, TransactionReceipt } from "viem"; import { BotConfig, TakeOrderDetails, TokenDetails, ViemClient } from "./types"; -import { DataFetcher, DataFetcherOptions, LiquidityProviders, Router } from "sushi/router"; +import { RainDataFetcher, DataFetcherOptions, LiquidityProviders, Router } from "sushi/router"; /** * One ether which equals to 1e18 @@ -159,7 +159,7 @@ export async function getEthPrice( targetTokenAddress: string, targetTokenDecimals: number, gasPrice: BigNumber, - dataFetcher: DataFetcher, + dataFetcher: RainDataFetcher, options?: DataFetcherOptions, fetchPools = true, ): Promise { @@ -649,7 +649,7 @@ export async function getRpSwap( toToken: Type, receiverAddress: string, routeProcessorAddress: string, - dataFetcher: DataFetcher, + dataFetcher: RainDataFetcher, gasPrice: BigNumber, lps?: LiquidityProviders[], ) { diff --git a/test/e2e/e2e.test.js b/test/e2e/e2e.test.js index af4378b8..2c901b41 100644 --- a/test/e2e/e2e.test.js +++ b/test/e2e/e2e.test.js @@ -232,6 +232,7 @@ for (let i = 0; i < testData.length; i++) { config.arbAddress = arb.address; config.orderbookAddress = orderbook.address; config.testBlockNumber = BigInt(blockNumber); + config.testBlockNumberTemp = BigInt(blockNumber); config.gasCoveragePercentage = "1"; config.viemClient = viemClient; config.dataFetcher = dataFetcher; diff --git a/test/processPair.test.js b/test/processPair.test.js index c4882888..c68608ba 100644 --- a/test/processPair.test.js +++ b/test/processPair.test.js @@ -71,6 +71,7 @@ describe("Test process pair", async function () { dataFetcher = { fetchPoolsForToken: async () => {}, fetchedPairPools: [], + updatePools: async () => {}, }; // 0xe0e530b7 viemClient = {