Skip to content

Commit

Permalink
fix: not-address specific log checking
Browse files Browse the repository at this point in the history
  • Loading branch information
mfw78 committed May 10, 2024
1 parent c98304d commit 6b84bce
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions src/services/chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,14 @@ 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,
isRunningInKubernetesPod,
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
Expand Down Expand Up @@ -506,22 +505,32 @@ async function processBlock(
}
}

function pollContractForEvents(
async function pollContractForEvents(
fromBlock: number,
toBlock: number | "latest",
context: ChainContext
): Promise<ConditionalOrderCreatedEvent[]> {
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) {
Expand Down

0 comments on commit 6b84bce

Please sign in to comment.