-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetAllGraduatedEvents.ts
50 lines (39 loc) · 1.86 KB
/
getAllGraduatedEvents.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
import hre from "hardhat";
import {unsparkingAIProxy, ffactoryProxy} from "./arguments/sparkFactoryArgs"
(async () => {
try {
const UnSparkingAI = await hre.ethers.getContractFactory("UnSparkingAI");
const unSparkingAI = await UnSparkingAI.attach(unsparkingAIProxy);
const FFactory = await hre.ethers.getContractFactory("FFactory");
const fFactory = await FFactory.attach(ffactoryProxy);
// Get all "event Graduated(address indexed token, address agentToken)"" events from the contract
const graduatedEvents = await unSparkingAI.queryFilter(
unSparkingAI.filters.Graduated()
);
// Uncomment to get the value of l from UnSparkingAI contract
// const l = await unSparkingAI.l();
const l = BigInt("6000000000000000000000")
let totalsrk = BigInt("0")
// Log all graduated events
for (let event of graduatedEvents) {
if ('args' in event && typeof event.args.token !== 'undefined' && typeof event.args.agentToken !== 'undefined') {
console.log(`Graduated token: ${event.args.token}, Agent Token: ${event.args.agentToken}`);
const pairContract = await fFactory.getPair(event.args.token, event.args.agentToken);
console.log(`Pair Contract Address: ${pairContract}`);
const FPair = await hre.ethers.getContractFactory("FPair");
const fPair = await FPair.attach(pairContract);
// Get the reserves of the pair contract
const reserves = await fPair.getReserves();
const reserve1 = BigInt(reserves[1].toString()) - l;
console.log(`Reserves: ${reserves[0]} ai token, ${reserve1} srk`);
totalsrk += reserve1;
console.log('---')
} else {
console.error('Invalid event format');
}
}
console.log("Total SRK: ", totalsrk.toString());
} catch (e) {
console.log(e);
}
})();