diff --git a/src/services/chain.ts b/src/services/chain.ts index 9543417..bb3060e 100644 --- a/src/services/chain.ts +++ b/src/services/chain.ts @@ -16,7 +16,7 @@ import { } from "@cowprotocol/cow-sdk"; import { addContract } from "../domain/events"; import { checkForAndPlaceOrder } from "../domain/polling"; -import { EventFilter, providers } from "ethers"; +import { ethers, providers } from "ethers"; import { composableCowContract, getLogger, @@ -24,7 +24,6 @@ import { metrics, } from "../utils"; import { DBService } from "."; -import { hexZeroPad } from "ethers/lib/utils"; import { policy } from "../domain/polling/filtering"; const WATCHDOG_FREQUENCY_SECS = 5; // 5 seconds @@ -506,22 +505,32 @@ async function processBlock( } } -function pollContractForEvents( +async function pollContractForEvents( fromBlock: number, toBlock: number | "latest", context: ChainContext ): Promise { - const { provider, chainId, addresses } = context; + const { provider, chainId } = context; const composableCow = composableCowContract(provider, chainId); - const filter = composableCow.filters.ConditionalOrderCreated() as EventFilter; + const eventName = "ConditionalOrderCreated(address,(address,bytes32,bytes))"; + const topic = ethers.utils.id(eventName); - if (addresses) { - filter.topics?.push( - addresses.map((address) => hexZeroPad(address.toLowerCase(), 32)) - ); - } + const logs = await provider.getLogs({ + fromBlock, + toBlock, + topics: [topic], + }); - return composableCow.queryFilter(filter, fromBlock, toBlock); + return logs + .map((e) => { + try { + return composableCow.interface.decodeEventLog(topic, e.data, e.topics) + .args as ConditionalOrderCreatedEvent; + } catch { + return null; + } + }) + .filter((e): e is ConditionalOrderCreatedEvent => e !== null); } function _formatResult(result: boolean) {