forked from paraswap/paraswap-dex-lib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfetch-event-blocknumber.ts
51 lines (47 loc) · 1.5 KB
/
fetch-event-blocknumber.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import dotenv from 'dotenv';
dotenv.config();
import { Contract } from '@ethersproject/contracts';
import { StaticJsonRpcProvider, Provider } from '@ethersproject/providers';
import { Network } from '../src/constants';
import { Address } from '../src/types';
import { generateConfig } from '../src/config';
// TODO: Import correct ABI
import ABI from '../src/abi/erc20.json';
// This is a helper script to fetch blockNumbers where a certain
// event was released by a certain contract
async function getBlockNumbersForEvents(
contractAddress: Address,
contractABI: any,
eventNames: string[],
blocksBack: number,
blocksToCheck: number,
provider: Provider,
) {
const blockNumber = (await provider.getBlockNumber()) - blocksBack;
const contract = new Contract(contractAddress, contractABI, provider);
for (let eventName of eventNames) {
console.log(
eventName,
'topic',
contract.interface.getEventTopic(eventName),
);
const logs = await contract.queryFilter(
contract.filters[eventName](),
blockNumber - blocksToCheck,
blockNumber,
);
console.log(
eventName,
logs.map((val: any) => val.blockNumber),
);
}
}
// TODO: Set your values here
const network = Network.AVALANCHE;
const eventNames = ['Transfer'];
const address = '0xc0253c3cc6aa5ab407b5795a04c28fb063273894';
const provider = new StaticJsonRpcProvider(
generateConfig(network).privateHttpProvider,
network,
);
getBlockNumbersForEvents(address, ABI, eventNames, 0, 2000, provider);