Skip to content

Commit

Permalink
feat(staking): listener should get validator address anyhow
Browse files Browse the repository at this point in the history
  • Loading branch information
imsk17 committed Aug 15, 2024
1 parent 7a4edab commit 500f011
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
16 changes: 14 additions & 2 deletions src/handler/evm/utils/listenForStakingEvents.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { EntityManager } from "@mikro-orm/sqlite";
import type { JsonRpcProvider } from "ethers";
import type { EventBuilder } from "../..";
import type { TSupportedChains } from "../../../config";
import type { TSupportedChainTypes, TSupportedChains } from "../../../config";
import { ERC20Staking__factory } from "../../../contractsTypes/evm";
import { Block } from "../../../persistence/entities/block";
import type { LogInstance, StakeEventIter } from "../../types";
Expand Down Expand Up @@ -55,8 +55,20 @@ const listenForStakingEvents = (
}
for (const log of logs) {
const decoded = stakerInt.parseLog(log);
const receipt = await log.getTransactionReceipt();
if (!decoded) continue;
await cb(builder.staked(decoded.args.validatorAddressAndChainType));
await cb(
builder.staked(
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
decoded.args.validatorAddressAndChainType.map((e: any) => {
return {
caller: receipt.from,
chainType: e.chainType as TSupportedChainTypes,
validatorAddress: e.validatorAddress,
};
}),
),
);
}
lastBlock = latestBlock;
await em.upsert(Block, {
Expand Down
5 changes: 1 addition & 4 deletions src/handler/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,7 @@ export async function listenStakeEvents(
log.info("Listening for Staking Events");

chain.listenForStakingEvents(builder, async (ev) => {
const stakerAddress = ev.find(
(item) => item.chainType === "evm",
)?.validatorAddress;
if (!stakerAddress) return;
const stakerAddress = ev[0].caller;

const signatures: {
validatorAddress: string;
Expand Down
1 change: 1 addition & 0 deletions src/handler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export type LockEvent = {

export type StakeEvent = {
validatorAddress: string;
caller: string;
chainType: TSupportedChainTypes;
}[];

Expand Down

0 comments on commit 500f011

Please sign in to comment.