mirror of
https://github.com/luxfi/uma.git
synced 2026-07-27 05:11:41 +00:00
feat: improve dvm2.0 monitor scripts duration (#4540)
Signed-off-by: Pablo Maldonado <pablo@umaproject.org>
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
import { delay } from "@uma/financial-templates-lib";
|
||||
import { Promise } from "bluebird";
|
||||
import { Contract, Event, EventFilter } from "ethers";
|
||||
|
||||
@@ -6,6 +5,9 @@ const defaultConcurrency = 200;
|
||||
const maxRetries = 3;
|
||||
const retrySleepTime = 10;
|
||||
|
||||
function delay(s: number) {
|
||||
return new Promise((resolve) => setTimeout(resolve, s * 1000));
|
||||
}
|
||||
export interface EventSearchConfig {
|
||||
fromBlock: number;
|
||||
toBlock: number;
|
||||
@@ -10,3 +10,4 @@ export * from "./UniswapV3Helpers";
|
||||
export * from "./types";
|
||||
export * from "./EthersSignerUtils";
|
||||
export * from "./EthersProviderUtils";
|
||||
export * from "./EventUtils";
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { getContractInstanceWithProvider, Logger, MonitoringParams, OptimisticOracleV3Ethers } from "./common";
|
||||
import { logSettleAssertion } from "./BotLogger";
|
||||
import { paginatedEventQuery } from "../utils/EventUtils";
|
||||
import { paginatedEventQuery } from "@uma/common";
|
||||
import {
|
||||
AssertionSettledEvent,
|
||||
AssertionMadeEvent,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { OptimisticOracleEthers, OptimisticOracleV2Ethers } from "@uma/contracts-node";
|
||||
import { ProposePriceEvent } from "@uma/contracts-node/dist/packages/contracts-node/typechain/core/ethers/OptimisticOracleV2";
|
||||
import { Networker } from "@uma/financial-templates-lib";
|
||||
import { paginatedEventQuery } from "../utils/EventUtils";
|
||||
import { paginatedEventQuery } from "@uma/common";
|
||||
import {
|
||||
Logger,
|
||||
MonitoringParams,
|
||||
|
||||
@@ -1,16 +1,15 @@
|
||||
import { getRetryProvider } from "@uma/common";
|
||||
import { getRetryProvider, paginatedEventQuery } from "@uma/common";
|
||||
import { aggregateTransactionsAndCall, NetworkerInterface, TransactionDataDecoder } from "@uma/financial-templates-lib";
|
||||
import { getContractInstanceWithProvider } from "../utils/contracts";
|
||||
|
||||
import type { Provider } from "@ethersproject/abstract-provider";
|
||||
import request from "graphql-request";
|
||||
|
||||
import { ethers } from "ethers";
|
||||
import { Event, ethers } from "ethers";
|
||||
|
||||
import { Multicall3Ethers } from "@uma/contracts-node";
|
||||
import { ProposePriceEvent } from "@uma/contracts-node/dist/packages/contracts-node/typechain/core/ethers/OptimisticOracleV2";
|
||||
import Web3 from "web3";
|
||||
import { paginatedEventQuery } from "../utils/EventUtils";
|
||||
|
||||
export { Logger } from "@uma/financial-templates-lib";
|
||||
export { getContractInstanceWithProvider } from "../utils/contracts";
|
||||
@@ -224,7 +223,7 @@ export const getOrderFilledEvents = async (
|
||||
maxBlockLookBack,
|
||||
};
|
||||
|
||||
const events = await paginatedEventQuery(
|
||||
const events: Event[] = await paginatedEventQuery(
|
||||
ctfExchange,
|
||||
ctfExchange.filters.OrderFilled(null, null, null, null, null, null, null, null),
|
||||
searchConfig
|
||||
|
||||
+1
-8
@@ -25,14 +25,7 @@ async function main() {
|
||||
await updateTrackers(votingV2, uniqueVoters);
|
||||
|
||||
console.log("Unstaking from all voters");
|
||||
for (const voter of uniqueVoters) {
|
||||
try {
|
||||
await unstakeFromStakedAccount(votingV2, voter);
|
||||
} catch (err) {
|
||||
console.log("Unstake failed for voter", voter, err);
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
await Promise.all(uniqueVoters.map((voter) => unstakeFromStakedAccount(votingV2, voter)));
|
||||
|
||||
const numberSlashedEvents = await getNumberSlashedEvents(votingV2);
|
||||
const votingV2BalanceWithoutExternalTransfers = await votingV2VotingBalanceWithoutExternalTransfers(
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers";
|
||||
import { computeVoteHashAncillary, getRandomSignedInt } from "@uma/common";
|
||||
import { computeVoteHashAncillary, getRandomSignedInt, paginatedEventQuery } from "@uma/common";
|
||||
import { VotingTokenEthers, VotingV2Ethers, TypedEventFilterEthers as TypedEventFilter } from "@uma/contracts-node";
|
||||
import { BigNumber, BigNumberish, BytesLike, Signer } from "ethers";
|
||||
import { getContractInstance } from "./contracts";
|
||||
import { forkNetwork, getForkChainId, increaseEvmTime } from "./utils";
|
||||
import { StakedEvent } from "@uma/contracts-node/dist/packages/contracts-node/typechain/core/ethers/VotingV2";
|
||||
import { VoterSlashedEvent } from "@uma/contracts-node/typechain/core/ethers/VotingV2";
|
||||
import { TransferEvent } from "@uma/contracts-node/dist/packages/contracts-node/typechain/core/ethers/ERC20";
|
||||
|
||||
const hre = require("hardhat");
|
||||
const { ethers } = hre;
|
||||
@@ -21,6 +24,14 @@ export interface CommittedVote {
|
||||
voteHash: BytesLike;
|
||||
}
|
||||
|
||||
const getVotingV2EventSearchConfig = async (votingV2: VotingV2Ethers) => {
|
||||
return {
|
||||
fromBlock: 16697232, // VotingV2 deployment block
|
||||
toBlock: await votingV2.provider.getBlockNumber(),
|
||||
maxBlockLookBack: 20000, // Mainnet max block lookback
|
||||
};
|
||||
};
|
||||
|
||||
export const getVotingContracts = async (): Promise<{ votingV2: VotingV2Ethers; votingToken: VotingTokenEthers }> => {
|
||||
let chainId: number;
|
||||
if (hre.network.name === "localhost") {
|
||||
@@ -39,34 +50,51 @@ export const getVotingContracts = async (): Promise<{ votingV2: VotingV2Ethers;
|
||||
};
|
||||
|
||||
export const getUniqueVoters = async (votingV2: VotingV2Ethers): Promise<string[]> => {
|
||||
const stakedEvents = await votingV2.queryFilter(votingV2.filters.Staked(null, null, null));
|
||||
const searchConfig = await getVotingV2EventSearchConfig(votingV2);
|
||||
const stakedEvents = (await paginatedEventQuery<StakedEvent>(
|
||||
votingV2,
|
||||
votingV2.filters.Staked(null, null, null),
|
||||
searchConfig
|
||||
)) as StakedEvent[];
|
||||
const uniqueVoters = new Set<string>(stakedEvents.map((event) => event.args.voter));
|
||||
return Array.from(uniqueVoters);
|
||||
};
|
||||
|
||||
export const updateTrackers = async (votingV2: VotingV2Ethers, voters: string[]): Promise<void> => {
|
||||
console.log("Updating trackers for all voters");
|
||||
// process voters in batches of 25 to avoid hitting the gas limit with multicall
|
||||
const batchSize = 25;
|
||||
const batches = [];
|
||||
for (let i = 0; i < voters.length; i += batchSize) {
|
||||
const batch = voters.slice(i, i + batchSize);
|
||||
const tx = await votingV2.multicall(
|
||||
batch.map((voter) => votingV2.interface.encodeFunctionData("updateTrackers", [voter]))
|
||||
batches.push(
|
||||
votingV2
|
||||
.multicall(batch.map((voter) => votingV2.interface.encodeFunctionData("updateTrackers", [voter])))
|
||||
.then((tx) => tx.wait())
|
||||
);
|
||||
await tx.wait();
|
||||
}
|
||||
await Promise.all(batches);
|
||||
console.log("Done updating trackers for all voters");
|
||||
};
|
||||
|
||||
export const getSumSlashedEvents = async (votingV2: VotingV2Ethers): Promise<BigNumber> => {
|
||||
const voterSlashedEvents = await votingV2.queryFilter(votingV2.filters.VoterSlashed(), 0, "latest");
|
||||
const searchConfig = await getVotingV2EventSearchConfig(votingV2);
|
||||
const voterSlashedEvents = (await paginatedEventQuery<VoterSlashedEvent>(
|
||||
votingV2,
|
||||
votingV2.filters.VoterSlashed(),
|
||||
searchConfig
|
||||
)) as VoterSlashedEvent[];
|
||||
return voterSlashedEvents
|
||||
.map((voterSlashedEvent) => voterSlashedEvent.args.slashedTokens)
|
||||
.reduce((a, b) => a.add(b), ethers.BigNumber.from(0));
|
||||
};
|
||||
|
||||
export const getNumberSlashedEvents = async (votingV2: VotingV2Ethers): Promise<number> => {
|
||||
const voterSlashedEvents = await votingV2.queryFilter(votingV2.filters.VoterSlashed(), 0, "latest");
|
||||
const searchConfig = await getVotingV2EventSearchConfig(votingV2);
|
||||
const voterSlashedEvents = (await paginatedEventQuery<VoterSlashedEvent>(
|
||||
votingV2,
|
||||
votingV2.filters.VoterSlashed(),
|
||||
searchConfig
|
||||
)) as VoterSlashedEvent[];
|
||||
return voterSlashedEvents.length;
|
||||
};
|
||||
|
||||
@@ -74,11 +102,12 @@ export const getVotingTokenExternalTransfersAmount = async (
|
||||
votingToken: VotingTokenEthers,
|
||||
votingV2: VotingV2Ethers
|
||||
): Promise<BigNumber> => {
|
||||
const transferEvents = await votingToken.queryFilter(
|
||||
const searchConfig = await getVotingV2EventSearchConfig(votingV2);
|
||||
const transferEvents = (await paginatedEventQuery<TransferEvent>(
|
||||
votingToken,
|
||||
votingToken.filters.Transfer(null, votingV2.address, null),
|
||||
0,
|
||||
"latest"
|
||||
);
|
||||
searchConfig
|
||||
)) as TransferEvent[];
|
||||
|
||||
let sumExternalTransfers = BigNumber.from(0);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user