-
Notifications
You must be signed in to change notification settings - Fork 0
/
manuallySettleVotes.ts
92 lines (75 loc) · 2.45 KB
/
manuallySettleVotes.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import BotSwarm, { Task } from "@federationwtf/botswarm";
import {
FederationNounsGovernor,
FederationNounsRelayer,
NounsDAOLogicV3,
} from "@federationwtf/botswarm/contracts";
import Relic from "@relicprotocol/client";
import { ethers } from "ethers";
import { Provider } from "zksync-web3";
const { Ethereum, log } = BotSwarm();
const mainnetProvider = new ethers.providers.JsonRpcProvider(
"https://rpc.flashbots.net/"
);
const zkSyncProvider = new Provider("https://mainnet.era.zksync.io");
const relic = await Relic.RelicClient.fromProviders(
zkSyncProvider,
mainnetProvider
);
const { addTask, watch, read, clients, contracts, schedule } = Ethereum({
contracts: {
FederationNounsGovernor,
FederationNounsRelayer,
NounsDAOLogicV3,
},
hooks: {
getBlockProof: async (task) => {
log.active(`Getting block proof for block ${task.execute.args[1]}`);
const { hash } = await clients.mainnet.getTransaction({
blockNumber: task.execute.args[1],
index: 0,
});
console.log("hash", hash);
const receipt = await mainnetProvider.getTransactionReceipt(hash);
console.log("receipt", receipt);
const { proof } = await relic.transactionProver.getProofData(receipt);
console.log("block proof", proof);
const newTask = {
...task,
execute: { ...task.execute, args: [task.execute.args[0], proof] },
} satisfies Task;
console.log("newTask", newTask);
return newTask;
},
},
privateKey: process.env.ETHEREUM_PRIVATE_KEY as string,
});
async function settleVotes(event: { args: { proposal: bigint } }) {
const [, , , , , , , , , , , castWindow, finalityBlocks] = await read({
contract: "FederationNounsGovernor",
chain: "zkSync",
functionName: "config",
});
const { endBlock } = await read({
contract: "FederationNounsGovernor",
chain: "zkSync",
functionName: "getProposal",
args: [event.args.proposal],
});
addTask({
schedule: {
block: endBlock - (castWindow + finalityBlocks) + 150n, // 150 blocks is ~30 minutes and finality is ~15 minutes
chain: "mainnet",
},
execute: {
hooks: ["getBlockProof"],
contract: "FederationNounsGovernor",
chain: "zkSync",
functionName: "settleVotes",
// @ts-ignore
args: [event.args.proposal, endBlock - (castWindow + finalityBlocks)],
},
});
}
// settleVotes({ args: { proposal: 482n } });
settleVotes({ args: { proposal: 483n } });