Skip to content

Commit

Permalink
add xcm fee balance monitor
Browse files Browse the repository at this point in the history
  • Loading branch information
RomeroYang committed Jun 21, 2024
1 parent 6ba1f45 commit 97de7e5
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -59,6 +60,9 @@ const runloop = () => {
relayChainTokenCheck("Acala", true);

relayChainTokenCheck("AssetHub", true);

xcmFeeTokenCheck("Karura", true);
xcmFeeTokenCheck("Acala", true);
}
}, 1000 * 60 * 60);
};
Expand Down
46 changes: 46 additions & 0 deletions src/monitors/xcmFeeTokenCheck.ts
Original file line number Diff line number Diff line change
@@ -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;
}
};

0 comments on commit 97de7e5

Please sign in to comment.