From 97de7e5d6fe27b24eb9b703edcd0c3f0f3fd6102 Mon Sep 17 00:00:00 2001 From: shawn Date: Fri, 21 Jun 2024 15:15:38 +0800 Subject: [PATCH] add xcm fee balance monitor --- src/index.ts | 4 +++ src/monitors/xcmFeeTokenCheck.ts | 46 ++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 src/monitors/xcmFeeTokenCheck.ts diff --git a/src/index.ts b/src/index.ts index 12168d2..d162c82 100644 --- a/src/index.ts +++ b/src/index.ts @@ -8,6 +8,7 @@ import { incenticesCheck } from "./monitors/incenticesCheck"; import { pushTelemetryLog, startTelemetry } from "./monitors/telemetry"; import { readReferendumFromFile, referendumCheck } from "./monitors/referendumCheck"; import { relayChainTokenCheck } from "./monitors/relayChainToken"; +import { xcmFeeTokenCheck } from "./monitors/xcmFeeTokenCheck"; import Koa from "koa"; // import { dexPoolCheck } from "./servers/dexPoolCheck"; @@ -59,6 +60,9 @@ const runloop = () => { relayChainTokenCheck("Acala", true); relayChainTokenCheck("AssetHub", true); + + xcmFeeTokenCheck("Karura", true); + xcmFeeTokenCheck("Acala", true); } }, 1000 * 60 * 60); }; diff --git a/src/monitors/xcmFeeTokenCheck.ts b/src/monitors/xcmFeeTokenCheck.ts new file mode 100644 index 0000000..81b3fb6 --- /dev/null +++ b/src/monitors/xcmFeeTokenCheck.ts @@ -0,0 +1,46 @@ +import { FixedPointNumber } from "@acala-network/sdk-core"; +import { Logger, getAcaApi, getKarApi } from "../utils"; + +const account_hydraDX = "23UvQ3ZWXwinF3JfBcxFBFadwDAAw9wwjAGbUVb1Ttf88vWw"; +const account_manta = "23UvQ3YsGN9m9waJAWhZW3yxQ25h3XTvVJ7rio8zPWTPYSh3"; +const account_basilisk = "qubt4U1h5dma9n4reFL3gW7kCXGv79AjTv6ewYXBgnqowye"; + +const min_balance = 2; + +export const xcmFeeTokenCheck = async (env = "Karura", toSlack = false) => { + let msg = ""; + let isError = false; + const token = env === "Karura" ? "KAR" : "ACA"; + if (token === "KAR") { + const account = await getKarApi().query.system.account(account_basilisk); + const balance = FixedPointNumber.fromInner(account.data.free.add(account.data.reserved).toString(), 12).toNumber(4); + msg = `${balance < min_balance ? "🚨" : "✅"} ${token} Balacne in Basilisk Account: ${balance}`; + isError = balance < min_balance; + } else { + const hydraAccount = await getAcaApi().query.system.account(account_hydraDX); + const mantaAccount = await getAcaApi().query.system.account(account_manta); + const hydraBalance = FixedPointNumber.fromInner( + hydraAccount.data.free.add(hydraAccount.data.reserved).toString(), + 12 + ).toNumber(4); + const mantaBalance = FixedPointNumber.fromInner( + mantaAccount.data.free.add(mantaAccount.data.reserved).toString(), + 12 + ).toNumber(4); + + msg = `${hydraBalance < min_balance ? "🚨" : "✅"} ${token} Balacne in HydraDX Account: ${hydraBalance} +${mantaBalance < min_balance ? "🚨" : "✅"} ${token} Balacne in Manta Account: ${mantaBalance}`; + isError = hydraBalance < min_balance || mantaBalance < min_balance; + } + + if (toSlack) { + const title = `[${env} Mainnet] XCM Fee Balance Check`; + Logger.pushEvent( + `${title}`, + `%%% \n${msg} \n %%% @slack-watchdog <@UPZRWB4UD>`, + "normal", + isError ? "error" : "info" + ); + return; + } +};