Skip to content

Commit

Permalink
feat: dvm v2 monitor bots (#4317)
Browse files Browse the repository at this point in the history
* feat: implement dvm v2 unstake monitor

Signed-off-by: Reinis Martinsons <reinis@umaproject.org>

* feat: implement dvm v2 stake monitor

Signed-off-by: Reinis Martinsons <reinis@umaproject.org>

* feat: implement dvm v2 proposal monitor

Signed-off-by: Reinis Martinsons <reinis@umaproject.org>

* feat: implement dvm v2 deletion proposal monitor

Signed-off-by: Reinis Martinsons <reinis@umaproject.org>

* feat: implement dvm v2 emergency proposal monitor

Signed-off-by: Reinis Martinsons <reinis@umaproject.org>

* feat: implement dvm v2 rolled votes monitor

Signed-off-by: Reinis Martinsons <reinis@umaproject.org>

* fix dvm monitor logger imports

Signed-off-by: Reinis Martinsons <reinis@umaproject.org>

* feat: update dvm2.0 upgrade script (#4304)

* feat: update dvm2.0 upgrade script

Signed-off-by: Pablo Maldonado <pablo@umaproject.org>

* feat: update starting index

Signed-off-by: Pablo Maldonado <pablo@umaproject.org>

* refactor: update comments

Signed-off-by: Pablo Maldonado <pablo@umaproject.org>

* feat: update starting index and starting id

Signed-off-by: Pablo Maldonado <pablo@umaproject.org>

* fix: governor starting id

Signed-off-by: Pablo Maldonado <pablo@umaproject.org>

* fix: add previous voting contracts events

Signed-off-by: Pablo Maldonado <pablo@umaproject.org>

* fix: add previous voting contracts events docs

Signed-off-by: Pablo Maldonado <pablo@umaproject.org>

* refator: improve comment

Signed-off-by: Pablo Maldonado <pablo@umaproject.org>

Signed-off-by: Pablo Maldonado <pablo@umaproject.org>
Co-authored-by: Pablo Maldonado <pablo@umaproject.org>
Co-authored-by: chrismaree <christopher.maree@gmail.com>
Signed-off-by: Reinis Martinsons <reinis@umaproject.org>

* fix: address issue in CI (#4315)

Signed-off-by: Reinis Martinsons <reinis@umaproject.org>

* build(deps): bump decode-uri-component from 0.2.0 to 0.2.2 (#4301)

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: chrismaree <christopher.maree@gmail.com>
Signed-off-by: Reinis Martinsons <reinis@umaproject.org>

* chore: Bump ethers to 5.7.x in common and sdk (#4214)

Co-authored-by: chrismaree <christopher.maree@gmail.com>
Signed-off-by: Reinis Martinsons <reinis@umaproject.org>

* feat: add new health check runner package (#4311)

Signed-off-by: Reinis Martinsons <reinis@umaproject.org>

* improve: Add MerkleTree improvements made in across-protocol/contracts-v2 (#4318)

Signed-off-by: Reinis Martinsons <reinis@umaproject.org>

* feat: new release (#4322)

* feat: new release

Captures MerkleTree util change to match across-protocol/contracts-v2

* Update CHANGELOG.md

* Update CHANGELOG.md

* lint

Signed-off-by: Reinis Martinsons <reinis@umaproject.org>

* feat: Add mainnet forking test case (#4306)

Signed-off-by: Reinis Martinsons <reinis@umaproject.org>

* fix[OA-audit-L03]: Address erronous docstrings and comments (#4320)

Signed-off-by: Reinis Martinsons <reinis@umaproject.org>

* fix[OA-audit-N04]: Add additional index paramaters (#4323)

Signed-off-by: Reinis Martinsons <reinis@umaproject.org>

* fix[OA-audit-N05]: Address argument name mismatches between interface and implementation (#4324)

Signed-off-by: Reinis Martinsons <reinis@umaproject.org>

* fix[OA-audit-N06]: Address Missing event parameter (#4325)

Signed-off-by: Reinis Martinsons <reinis@umaproject.org>

* fix[OA-audit-N07]: Fix licencing issues accross the OA (#4326)

Signed-off-by: Reinis Martinsons <reinis@umaproject.org>

* fix[OA-audit-N08]: Fix address multicaller payability (#4327)

Signed-off-by: Reinis Martinsons <reinis@umaproject.org>

* fix[OA-audit-N09]: Missing check for non-zero address (#4336)

Co-authored-by: Pablo Maldonado <pablo@umaproject.org>
Signed-off-by: Reinis Martinsons <reinis@umaproject.org>

* fix: use external functions in oa (#4337)

Signed-off-by: Reinis Martinsons <reinis@umaproject.org>

Signed-off-by: Reinis Martinsons <reinis@umaproject.org>

* fix: remove unused import (#4338)

Signed-off-by: Reinis Martinsons <reinis@umaproject.org>

Signed-off-by: Reinis Martinsons <reinis@umaproject.org>

* fix: dont use named return variables (#4341)

Signed-off-by: Reinis Martinsons <reinis@umaproject.org>

Signed-off-by: Reinis Martinsons <reinis@umaproject.org>

* fix[OA-audit-N10]: Fix redundant code (#4335)

* fix: remove override from base em

Signed-off-by: Reinis Martinsons <reinis@umaproject.org>

* fix: shared getRequestId function in full policy em

Signed-off-by: Reinis Martinsons <reinis@umaproject.org>

* fix: simplify require in configureEscalationManager

Signed-off-by: Reinis Martinsons <reinis@umaproject.org>

* fix: simplify em lookup in oa

Signed-off-by: Reinis Martinsons <reinis@umaproject.org>

* fix: store callback recipients as local variables in oa

Signed-off-by: Reinis Martinsons <reinis@umaproject.org>

* fix: redundant return in oa

Signed-off-by: Reinis Martinsons <reinis@umaproject.org>

* fix: remove forge-std lib

Signed-off-by: Reinis Martinsons <reinis@umaproject.org>

* fix: add back gitmodules

Signed-off-by: Reinis Martinsons <reinis@umaproject.org>

* fix: add newline in gitmodules

Signed-off-by: Reinis Martinsons <reinis@umaproject.org>

* fix: newline in gitmodules

Signed-off-by: Reinis Martinsons <reinis@umaproject.org>

* fix: shorten variable names

Signed-off-by: Reinis Martinsons <reinis@umaproject.org>

Signed-off-by: Reinis Martinsons <reinis@umaproject.org>

* fix[OA-audit-N12]: Typographical errors (#4339)

Signed-off-by: Pablo Maldonado <pablo@umaproject.org>

Signed-off-by: Pablo Maldonado <pablo@umaproject.org>
Signed-off-by: chrismaree <christopher.maree@gmail.com>
Signed-off-by: Reinis Martinsons <reinis@umaproject.org>
Co-authored-by: Pablo Maldonado <pablo@umaproject.org>
Co-authored-by: chrismaree <christopher.maree@gmail.com>
Co-authored-by: Reinis Martinsons <reinis@umaproject.org>
Signed-off-by: Reinis Martinsons <reinis@umaproject.org>

* fix[OA-audit-L01]: Limit ability for Full Policy Escalation Manager to setArbitrationResolution (#4319)

* fix: Limit ability for Full Policy EscilationManager to setArbitrationResolution

Signed-off-by: chrismaree <christopher.maree@gmail.com>

* fix

Signed-off-by: chrismaree <christopher.maree@gmail.com>

* Update packages/core/test/foundry/optimistic-asserter/escalation-manager/FullPolicyEscalationManager.t.sol

Signed-off-by: chrismaree <christopher.maree@gmail.com>
Signed-off-by: Reinis Martinsons <reinis@umaproject.org>
Co-authored-by: Reinis Martinsons <77973553+Reinis-FRP@users.noreply.github.com>
Co-authored-by: Reinis Martinsons <reinis@umaproject.org>
Signed-off-by: Reinis Martinsons <reinis@umaproject.org>

* fix[OA-audit-L02]: Lack of access control (#4334)

* fix[OA-audit-L02]: Lack of access control on potentially sensitive function

Signed-off-by: Pablo Maldonado <pablo@umaproject.org>

* test: test onlyOptimisticAsserter modifier

Signed-off-by: Pablo Maldonado <pablo@umaproject.org>

* fix

Signed-off-by: chrismaree <christopher.maree@gmail.com>

* Update packages/core/test/foundry/optimistic-asserter/escalation-manager/DisputeLimitingEscalationManager.t.sol

Co-authored-by: Reinis Martinsons <77973553+Reinis-FRP@users.noreply.github.com>

* Update packages/core/test/foundry/optimistic-asserter/escalation-manager/BaseEscalationManager.t.sol

Co-authored-by: Reinis Martinsons <77973553+Reinis-FRP@users.noreply.github.com>

* Update packages/core/test/foundry/optimistic-asserter/escalation-manager/DisputeLimitingEscalationManager.t.sol

Co-authored-by: Reinis Martinsons <77973553+Reinis-FRP@users.noreply.github.com>

* fix

Signed-off-by: chrismaree <christopher.maree@gmail.com>

* fix: remove Ownable from base em

Signed-off-by: Reinis Martinsons <reinis@umaproject.org>

* fix: reorder imports

Signed-off-by: Reinis Martinsons <reinis@umaproject.org>

Signed-off-by: Pablo Maldonado <pablo@umaproject.org>
Signed-off-by: chrismaree <christopher.maree@gmail.com>
Signed-off-by: Reinis Martinsons <reinis@umaproject.org>
Co-authored-by: Pablo Maldonado <pablo@umaproject.org>
Co-authored-by: chrismaree <christopher.maree@gmail.com>
Co-authored-by: Reinis Martinsons <77973553+Reinis-FRP@users.noreply.github.com>
Co-authored-by: Reinis Martinsons <reinis@umaproject.org>
Signed-off-by: Reinis Martinsons <reinis@umaproject.org>

* fix[OA-audit-N15]: Use of magic numbers (#4340)

Co-authored-by: Pablo Maldonado <pablo@umaproject.org>
Signed-off-by: Reinis Martinsons <reinis@umaproject.org>

* fix[OA-audit-L04]: Add missing or incomplete docstrings (#4342)

* fix: natspec in oa public methods

Signed-off-by: Reinis Martinsons <reinis@umaproject.org>

* fix: add docstrings to oa interface

Signed-off-by: Reinis Martinsons <reinis@umaproject.org>

* fix: add natspec to oa callback recipient interface

Signed-off-by: Reinis Martinsons <reinis@umaproject.org>

* fix: natspec in base em

Signed-off-by: Reinis Martinsons <reinis@umaproject.org>

* fix: natspec em interface

Signed-off-by: Reinis Martinsons <reinis@umaproject.org>

* fix: natspec full policy em

Signed-off-by: Reinis Martinsons <reinis@umaproject.org>

* fix:

Signed-off-by: Reinis Martinsons <reinis@umaproject.org>

* fix: add comments to internal oa functions

Signed-off-by: Reinis Martinsons <reinis@umaproject.org>

Signed-off-by: Reinis Martinsons <reinis@umaproject.org>

* fix[OA-audit-N03]: Always send oracle fee to the Store (#4343)

* fix: always pay oracle fee

Signed-off-by: Reinis Martinsons <reinis@umaproject.org>

* fix: lift zero fee check

Signed-off-by: Reinis Martinsons <reinis@umaproject.org>

Signed-off-by: Reinis Martinsons <reinis@umaproject.org>

* feat: refactor dmv monitoring to use single entry

Signed-off-by: Reinis Martinsons <reinis@umaproject.org>

* feat: add readme

Signed-off-by: Reinis Martinsons <reinis@umaproject.org>

* fix: readme

Signed-off-by: Reinis Martinsons <reinis@umaproject.org>

* feat: monitor governor transfers

Signed-off-by: Reinis Martinsons <reinis@umaproject.org>

* feat: monitor uma mints

Signed-off-by: Reinis Martinsons <reinis@umaproject.org>

* fix

Signed-off-by: Reinis Martinsons <reinis@umaproject.org>

* fix: rename common file

Signed-off-by: Reinis Martinsons <reinis@umaproject.org>

* Revert "fix: rename common file"

This reverts commit e674408.

Signed-off-by: Reinis Martinsons <reinis@umaproject.org>

* feat: rename dvm monitor

Signed-off-by: Reinis Martinsons <reinis@umaproject.org>

* fix: improve block update and add comments

Signed-off-by: Reinis Martinsons <reinis@umaproject.org>

* fix: add token units to readme

Signed-off-by: Reinis Martinsons <reinis@umaproject.org>

* fix: parse threshold parameters from main entry point

Signed-off-by: Reinis Martinsons <reinis@umaproject.org>

* fix: update block range only in main entry point

Signed-off-by: Reinis Martinsons <reinis@umaproject.org>

* fix: update log levels

Signed-off-by: Reinis Martinsons <reinis@umaproject.org>

* fix: typescript error

Signed-off-by: Reinis Martinsons <reinis@umaproject.org>

* feat: use tsc

Signed-off-by: Reinis Martinsons <reinis@umaproject.org>

* fix: update readme

Signed-off-by: Reinis Martinsons <reinis@umaproject.org>

* fix: monitor bots after dvm refactor

Signed-off-by: Reinis Martinsons <reinis@umaproject.org>

* fix:

Signed-off-by: Reinis Martinsons <reinis@umaproject.org>

* fix:

Signed-off-by: Reinis Martinsons <reinis@umaproject.org>

* fix:

Signed-off-by: Reinis Martinsons <reinis@umaproject.org>

* fix:

Signed-off-by: Reinis Martinsons <reinis@umaproject.org>

* fix:

Signed-off-by: Reinis Martinsons <reinis@umaproject.org>

Signed-off-by: Reinis Martinsons <reinis@umaproject.org>
Signed-off-by: Pablo Maldonado <pablo@umaproject.org>
Signed-off-by: chrismaree <christopher.maree@gmail.com>
Co-authored-by: Pablo Maldonado <pablomaldonadoturci@gmail.com>
Co-authored-by: Pablo Maldonado <pablo@umaproject.org>
Co-authored-by: chrismaree <christopher.maree@gmail.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: nicholaspai <9457025+nicholaspai@users.noreply.github.com>
  • Loading branch information
6 people authored Jan 10, 2023
1 parent cbff462 commit 5a6602e
Show file tree
Hide file tree
Showing 14 changed files with 622 additions and 47 deletions.
21 changes: 21 additions & 0 deletions packages/scripts/src/monitor-dvm/MonitorDeletion.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Logger } from "@uma/financial-templates-lib";
import { VotingV2Ethers } from "@uma/contracts-node";
import { logDeleted } from "./MonitorLogger";
import { getContractInstanceByUrl } from "../utils/contracts";
import type { MonitoringParams } from "./common";

export async function monitorDeletion(logger: typeof Logger, params: MonitoringParams): Promise<void> {
const votingV2 = await getContractInstanceByUrl<VotingV2Ethers>("VotingV2", params.jsonRpcUrl);

const deletedRequests = (
await votingV2.queryFilter(votingV2.filters.RequestDeleted(), params.blockRange.start, params.blockRange.end)
).map((event) => ({
tx: event.transactionHash,
identifier: event.args.identifier,
time: event.args.time,
ancillaryData: event.args.ancillaryData,
}));
deletedRequests.forEach((request) => {
logDeleted(logger, request, params.chainId);
});
}
27 changes: 27 additions & 0 deletions packages/scripts/src/monitor-dvm/MonitorEmergency.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { Logger } from "@uma/financial-templates-lib";
import { EmergencyProposerEthers } from "@uma/contracts-node";
import { logEmergencyProposal } from "./MonitorLogger";
import { getContractInstanceByUrl } from "../utils/contracts";
import type { MonitoringParams } from "./common";

export async function monitorEmergency(logger: typeof Logger, params: MonitoringParams): Promise<void> {
const emergencyProposer = await getContractInstanceByUrl<EmergencyProposerEthers>(
"EmergencyProposer",
params.jsonRpcUrl
);

const emergencyProposals = (
await emergencyProposer.queryFilter(
emergencyProposer.filters.EmergencyTransactionsProposed(),
params.blockRange.start,
params.blockRange.end
)
).map((event) => ({
tx: event.transactionHash,
id: event.args.id.toString(),
sender: event.args.sender,
}));
emergencyProposals.forEach((proposal) => {
logEmergencyProposal(logger, proposal, params.chainId);
});
}
19 changes: 19 additions & 0 deletions packages/scripts/src/monitor-dvm/MonitorGovernance.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Logger } from "@uma/financial-templates-lib";
import { GovernorV2Ethers } from "@uma/contracts-node";
import { logGovernanceProposal } from "./MonitorLogger";
import { getContractInstanceByUrl } from "../utils/contracts";
import type { MonitoringParams } from "./common";

export async function monitorGovernance(logger: typeof Logger, params: MonitoringParams): Promise<void> {
const governorV2 = await getContractInstanceByUrl<GovernorV2Ethers>("GovernorV2", params.jsonRpcUrl);

const governanceProposals = (
await governorV2.queryFilter(governorV2.filters.NewProposal(), params.blockRange.start, params.blockRange.end)
).map((event) => ({
tx: event.transactionHash,
id: event.args.id.toString(),
}));
governanceProposals.forEach((proposal) => {
logGovernanceProposal(logger, proposal, params.chainId);
});
}
27 changes: 27 additions & 0 deletions packages/scripts/src/monitor-dvm/MonitorGovernorTransfers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { Logger } from "@uma/financial-templates-lib";
import { VotingTokenEthers, getAddress } from "@uma/contracts-node";
import { logGovernorTransfer } from "./MonitorLogger";
import { getContractInstanceByUrl } from "../utils/contracts";
import type { MonitoringParams } from "./common";

export async function monitorGovernorTransfers(logger: typeof Logger, params: MonitoringParams): Promise<void> {
const votingToken = await getContractInstanceByUrl<VotingTokenEthers>("VotingToken", params.jsonRpcUrl);
const governorV2Address = await getAddress("GovernorV2", params.chainId);

const largeGovernorTransfers = (
await votingToken.queryFilter(
votingToken.filters.Transfer(governorV2Address, null),
params.blockRange.start,
params.blockRange.end
)
)
.filter((event) => event.args.value.gte(params.governorTransfersThreshold))
.map((event) => ({
tx: event.transactionHash,
to: event.args.to.toString(),
value: event.args.value.toString(),
}));
largeGovernorTransfers.forEach((transfer) => {
logGovernorTransfer(logger, transfer, params.chainId);
});
}
175 changes: 175 additions & 0 deletions packages/scripts/src/monitor-dvm/MonitorLogger.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
import { createEtherscanLinkMarkdown, createFormatFunction } from "@uma/common";
import { Logger } from "@uma/financial-templates-lib";
import { utils } from "ethers";
import { tryHexToUtf8String } from "./common";
import type { BigNumber } from "ethers";

export const logLargeUnstake = (
logger: typeof Logger,
unstake: {
tx: string;
address: string;
amount: string;
},
chainId: number
): void => {
logger.warn({
at: "DVMMonitor",
message: "Large unstake requested 😟",
mrkdwn:
createEtherscanLinkMarkdown(unstake.address, chainId) +
" requested unstake of " +
createFormatFunction(2, 2, false, 18)(unstake.amount) +
" UMA at " +
createEtherscanLinkMarkdown(unstake.tx, chainId),
});
};

export const logLargeStake = (
logger: typeof Logger,
stake: {
tx: string;
address: string;
amount: string;
},
chainId: number
): void => {
logger.warn({
at: "DVMMonitor",
message: "Large amount staked 🍖",
mrkdwn:
createEtherscanLinkMarkdown(stake.address, chainId) +
" staked " +
createFormatFunction(2, 2, false, 18)(stake.amount) +
" UMA at " +
createEtherscanLinkMarkdown(stake.tx, chainId),
});
};

export const logGovernanceProposal = (
logger: typeof Logger,
proposal: {
tx: string;
id: string;
},
chainId: number
): void => {
logger.warn({
at: "DVMMonitor",
message: "New governance proposal created 📜",
mrkdwn: "New Admin " + proposal.id + " proposal created at " + createEtherscanLinkMarkdown(proposal.tx, chainId),
});
};

export const logEmergencyProposal = (
logger: typeof Logger,
proposal: {
tx: string;
id: string;
sender: string;
},
chainId: number
): void => {
logger.error({
at: "DVMMonitor",
message: "New emergency proposal created 🚨",
mrkdwn:
proposal.sender +
" submitted new emergency proposal #" +
proposal.id +
" at " +
createEtherscanLinkMarkdown(proposal.tx, chainId),
});
};

export const logDeleted = (
logger: typeof Logger,
request: {
tx: string;
identifier: string;
time: BigNumber;
ancillaryData: string;
},
chainId: number
): void => {
logger.error({
at: "DVMMonitor",
message: "Request deleted as spam 🔇",
mrkdwn:
"Request for identifier " +
utils.parseBytes32String(request.identifier) +
" at " +
new Date(Number(request.time) * 1000).toUTCString() +
" was deleted as spam at " +
createEtherscanLinkMarkdown(request.tx, chainId) +
". Ancillary data: " +
tryHexToUtf8String(request.ancillaryData),
});
};

export const logRolled = (
logger: typeof Logger,
request: {
tx: string;
identifier: string;
time: BigNumber;
ancillaryData: string;
},
chainId: number
): void => {
logger.error({
at: "DVMMonitor",
message: "Rolled request 🎲",
mrkdwn:
"Request for identifier " +
utils.parseBytes32String(request.identifier) +
" at " +
new Date(Number(request.time) * 1000).toUTCString() +
" was rolled at " +
createEtherscanLinkMarkdown(request.tx, chainId) +
". Ancillary data: " +
tryHexToUtf8String(request.ancillaryData),
});
};

export const logGovernorTransfer = (
logger: typeof Logger,
transfer: {
tx: string;
to: string;
value: string;
},
chainId: number
): void => {
logger.error({
at: "DVMMonitor",
message: "Large governor transfer 📤",
mrkdwn:
createFormatFunction(2, 2, false, 18)(transfer.value) +
" UMA was transferred from governor to " +
createEtherscanLinkMarkdown(transfer.to, chainId) +
" at " +
createEtherscanLinkMarkdown(transfer.tx, chainId),
});
};

export const logMint = (
logger: typeof Logger,
mint: {
tx: string;
to: string;
value: string;
},
chainId: number
): void => {
logger.error({
at: "DVMMonitor",
message: "Large UMA minting 💸",
mrkdwn:
createFormatFunction(2, 2, false, 18)(mint.value) +
" UMA was minted to " +
createEtherscanLinkMarkdown(mint.to, chainId) +
" at " +
createEtherscanLinkMarkdown(mint.tx, chainId),
});
};
27 changes: 27 additions & 0 deletions packages/scripts/src/monitor-dvm/MonitorMints.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { Logger } from "@uma/financial-templates-lib";
import { ZERO_ADDRESS } from "@uma/common";
import { VotingTokenEthers } from "@uma/contracts-node";
import { logMint } from "./MonitorLogger";
import { getContractInstanceByUrl } from "../utils/contracts";
import type { MonitoringParams } from "./common";

export async function monitorMints(logger: typeof Logger, params: MonitoringParams): Promise<void> {
const votingToken = await getContractInstanceByUrl<VotingTokenEthers>("VotingToken", params.jsonRpcUrl);

const largeMints = (
await votingToken.queryFilter(
votingToken.filters.Transfer(ZERO_ADDRESS, null),
params.blockRange.start,
params.blockRange.end
)
)
.filter((event) => event.args.value.gte(params.mintsThreshold))
.map((event) => ({
tx: event.transactionHash,
to: event.args.to.toString(),
value: event.args.value.toString(),
}));
largeMints.forEach((mint) => {
logMint(logger, mint, params.chainId);
});
}
21 changes: 21 additions & 0 deletions packages/scripts/src/monitor-dvm/MonitorRolled.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Logger } from "@uma/financial-templates-lib";
import { VotingV2Ethers } from "@uma/contracts-node";
import { logRolled } from "./MonitorLogger";
import { getContractInstanceByUrl } from "../utils/contracts";
import type { MonitoringParams } from "./common";

export async function monitorRolled(logger: typeof Logger, params: MonitoringParams): Promise<void> {
const votingV2 = await getContractInstanceByUrl<VotingV2Ethers>("VotingV2", params.jsonRpcUrl);

const rolledRequests = (
await votingV2.queryFilter(votingV2.filters.RequestRolled(), params.blockRange.start, params.blockRange.end)
).map((event) => ({
tx: event.transactionHash,
identifier: event.args.identifier,
time: event.args.time,
ancillaryData: event.args.ancillaryData,
}));
rolledRequests.forEach((request) => {
logRolled(logger, request, params.chainId);
});
}
22 changes: 22 additions & 0 deletions packages/scripts/src/monitor-dvm/MonitorStakes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { Logger } from "@uma/financial-templates-lib";
import { VotingV2Ethers } from "@uma/contracts-node";
import { logLargeStake } from "./MonitorLogger";
import { getContractInstanceByUrl } from "../utils/contracts";
import type { MonitoringParams } from "./common";

export async function monitorStakes(logger: typeof Logger, params: MonitoringParams): Promise<void> {
const votingV2 = await getContractInstanceByUrl<VotingV2Ethers>("VotingV2", params.jsonRpcUrl);

const largeStakes = (
await votingV2.queryFilter(votingV2.filters.Staked(), params.blockRange.start, params.blockRange.end)
)
.filter((event) => event.args.amount.gte(params.stakeThreshold))
.map((event) => ({
tx: event.transactionHash,
address: event.args.voter,
amount: event.args.amount.toString(),
}));
largeStakes.forEach((stake) => {
logLargeStake(logger, stake, params.chainId);
});
}
22 changes: 22 additions & 0 deletions packages/scripts/src/monitor-dvm/MonitorUnstakes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { Logger } from "@uma/financial-templates-lib";
import { VotingV2Ethers } from "@uma/contracts-node";
import { logLargeUnstake } from "./MonitorLogger";
import { getContractInstanceByUrl } from "../utils/contracts";
import type { MonitoringParams } from "./common";

export async function monitorUnstakes(logger: typeof Logger, params: MonitoringParams): Promise<void> {
const votingV2 = await getContractInstanceByUrl<VotingV2Ethers>("VotingV2", params.jsonRpcUrl);

const largeUnstakes = (
await votingV2.queryFilter(votingV2.filters.RequestedUnstake(), params.blockRange.start, params.blockRange.end)
)
.filter((event) => event.args.amount.gte(params.unstakeThreshold))
.map((event) => ({
tx: event.transactionHash,
address: event.args.voter,
amount: event.args.amount.toString(),
}));
largeUnstakes.forEach((unstake) => {
logLargeUnstake(logger, unstake, params.chainId);
});
}
Loading

0 comments on commit 5a6602e

Please sign in to comment.