diff --git a/packages/crons/yarn.deploy.lock b/packages/crons/yarn.deploy.lock index e8dfab98f..1f7da0896 100644 --- a/packages/crons/yarn.deploy.lock +++ b/packages/crons/yarn.deploy.lock @@ -233,7 +233,6 @@ __metadata: cors: ^2.8.5 dotenv: ^16.0.3 fastify: ^4.13.0 - fastify-cron: ^1.3.1 git-format-staged: ^2.1.3 ky: ^0.31.4 nodemon: ^2.0.20 @@ -835,15 +834,6 @@ __metadata: languageName: node linkType: hard -"@types/cron@npm:^2.0.0": - version: 2.4.0 - resolution: "@types/cron@npm:2.4.0" - dependencies: - cron: "npm:*" - checksum: c763e99a757ea76aee435948c25e0bdaf32ec44c69603088c73e8832df6b121e87932709925fe3e94777833ca30845c31df1167be54c330cf458d348059b9ffc - languageName: node - linkType: hard - "@types/crypto-js@npm:^4.1.1": version: 4.1.1 resolution: "@types/crypto-js@npm:4.1.1" @@ -898,13 +888,6 @@ __metadata: languageName: node linkType: hard -"@types/luxon@npm:~3.3.0": - version: 3.3.2 - resolution: "@types/luxon@npm:3.3.2" - checksum: b9111132720eae0269538872a5a496b29587ecfc8edc3b0ff7d269aa93a5ff00a131b23d1e9d1f12ec39f2c779ad21bd8d9f90b122c85a182771aabde7f676b8 - languageName: node - linkType: hard - "@types/mime@npm:*": version: 3.0.1 resolution: "@types/mime@npm:3.0.1" @@ -1623,16 +1606,6 @@ __metadata: languageName: node linkType: hard -"cron@npm:*, cron@npm:^2.0.0": - version: 2.4.3 - resolution: "cron@npm:2.4.3" - dependencies: - "@types/luxon": "npm:~3.3.0" - luxon: "npm:~3.3.0" - checksum: cb0ad49653b37ba125f8670ca92150ce515493512b1b8a5e08086d22bec9c54dc6d8926fcdb49ea5783f6699862ca5fdc532a440ce33c3228f9b3d565010db2f - languageName: node - linkType: hard - "cross-fetch@npm:^3.1.5": version: 3.1.8 resolution: "cross-fetch@npm:3.1.8" @@ -1931,26 +1904,6 @@ __metadata: languageName: node linkType: hard -"fastify-cron@npm:^1.3.1": - version: 1.3.1 - resolution: "fastify-cron@npm:1.3.1" - dependencies: - "@types/cron": "npm:^2.0.0" - cron: "npm:^2.0.0" - fastify-plugin: "npm:^3.0.0" - peerDependencies: - fastify: ^4.1.0 - checksum: 152cc6bfe9ebd347747d922533e49b9ee0528d1c22677858046615a7bbae07166af7fd4f126c00f0c6d380aca33da6fa91f572c24cb586107753b03ab16392f9 - languageName: node - linkType: hard - -"fastify-plugin@npm:^3.0.0": - version: 3.0.1 - resolution: "fastify-plugin@npm:3.0.1" - checksum: 131ba0a388f777829c3fb0fd5b75cf057688ce6d0ca354fb1ebf829767a8c853b0825762b9185b5200097454df0ede2f3095da2efe1aa1b3736d07f194e6d374 - languageName: node - linkType: hard - "fastify-plugin@npm:^4.0.0": version: 4.5.1 resolution: "fastify-plugin@npm:4.5.1" @@ -2624,13 +2577,6 @@ __metadata: languageName: node linkType: hard -"luxon@npm:~3.3.0": - version: 3.3.0 - resolution: "luxon@npm:3.3.0" - checksum: 50cf17a0dc155c3dcacbeae8c0b7e80db425e0ba97b9cbdf12a7fc142d841ff1ab1560919f033af46240ed44e2f70c49f76e3422524c7fc8bb8d81ca47c66187 - languageName: node - linkType: hard - "make-error@npm:^1.1.1": version: 1.3.6 resolution: "make-error@npm:1.3.6" diff --git a/packages/distributor-oracle/package.json b/packages/distributor-oracle/package.json index 5fb371bde..85ada2aaf 100644 --- a/packages/distributor-oracle/package.json +++ b/packages/distributor-oracle/package.json @@ -54,7 +54,6 @@ "cors": "^2.8.5", "dotenv": "^16.0.3", "fastify": "^4.13.0", - "fastify-cron": "^1.3.1", "ky": "^0.31.4", "pg": "^8.9.0", "prom-client": "^15.0.0", diff --git a/packages/distributor-oracle/src/server.ts b/packages/distributor-oracle/src/server.ts index 7bb33d350..4112d5523 100644 --- a/packages/distributor-oracle/src/server.ts +++ b/packages/distributor-oracle/src/server.ts @@ -1,5 +1,4 @@ import dotenv from "dotenv"; -import fastifyCron from "fastify-cron"; dotenv.config(); // @ts-ignore import { @@ -195,22 +194,19 @@ export class OracleServer { server.get("/health", async () => { return { ok: true }; }); - server.register(fastifyCron, { - jobs: [ - { - cronTime: "0 * * * *", - runOnInit: true, - onTick: async () => { - console.log("Updating total rewards"); - const rewards = toNumber(new BN(await db.getTotalRewards()), 6); - totalRewardsGauge - .labels(DNT.toBase58()) - .set(Number(rewards)); - }, - }, - ], - }); + let lastCall = 0; + async function getTotalRewards() { + const currTs = new Date().valueOf(); + // Only update once every 10m + if (currTs - lastCall > 10 * 60 * 1000) { + console.log("Updating total rewards"); + const rewards = toNumber(new BN(await db.getTotalRewards()), 6); + totalRewardsGauge.labels(DNT.toBase58()).set(Number(rewards)); + lastCall = currTs; + } + } server.get("/metrics", async (request, reply) => { + await getTotalRewards(); return register.metrics(); }); diff --git a/packages/distributor-oracle/yarn.deploy.lock b/packages/distributor-oracle/yarn.deploy.lock index 8bb59b69d..86329370b 100644 --- a/packages/distributor-oracle/yarn.deploy.lock +++ b/packages/distributor-oracle/yarn.deploy.lock @@ -194,7 +194,6 @@ __metadata: cors: ^2.8.5 dotenv: ^16.0.3 fastify: ^4.13.0 - fastify-cron: ^1.3.1 git-format-staged: ^2.1.3 ky: ^0.31.4 nodemon: ^2.0.20 @@ -694,15 +693,6 @@ __metadata: languageName: node linkType: hard -"@types/cron@npm:^2.0.0": - version: 2.4.0 - resolution: "@types/cron@npm:2.4.0" - dependencies: - cron: "npm:*" - checksum: c763e99a757ea76aee435948c25e0bdaf32ec44c69603088c73e8832df6b121e87932709925fe3e94777833ca30845c31df1167be54c330cf458d348059b9ffc - languageName: node - linkType: hard - "@types/crypto-js@npm:^4.1.1": version: 4.1.1 resolution: "@types/crypto-js@npm:4.1.1" @@ -757,13 +747,6 @@ __metadata: languageName: node linkType: hard -"@types/luxon@npm:~3.3.0": - version: 3.3.2 - resolution: "@types/luxon@npm:3.3.2" - checksum: b9111132720eae0269538872a5a496b29587ecfc8edc3b0ff7d269aa93a5ff00a131b23d1e9d1f12ec39f2c779ad21bd8d9f90b122c85a182771aabde7f676b8 - languageName: node - linkType: hard - "@types/mime@npm:*": version: 3.0.1 resolution: "@types/mime@npm:3.0.1" @@ -1455,16 +1438,6 @@ __metadata: languageName: node linkType: hard -"cron@npm:*, cron@npm:^2.0.0": - version: 2.4.3 - resolution: "cron@npm:2.4.3" - dependencies: - "@types/luxon": "npm:~3.3.0" - luxon: "npm:~3.3.0" - checksum: cb0ad49653b37ba125f8670ca92150ce515493512b1b8a5e08086d22bec9c54dc6d8926fcdb49ea5783f6699862ca5fdc532a440ce33c3228f9b3d565010db2f - languageName: node - linkType: hard - "cross-fetch@npm:^3.1.5": version: 3.1.8 resolution: "cross-fetch@npm:3.1.8" @@ -1756,26 +1729,6 @@ __metadata: languageName: node linkType: hard -"fastify-cron@npm:^1.3.1": - version: 1.3.1 - resolution: "fastify-cron@npm:1.3.1" - dependencies: - "@types/cron": "npm:^2.0.0" - cron: "npm:^2.0.0" - fastify-plugin: "npm:^3.0.0" - peerDependencies: - fastify: ^4.1.0 - checksum: 152cc6bfe9ebd347747d922533e49b9ee0528d1c22677858046615a7bbae07166af7fd4f126c00f0c6d380aca33da6fa91f572c24cb586107753b03ab16392f9 - languageName: node - linkType: hard - -"fastify-plugin@npm:^3.0.0": - version: 3.0.1 - resolution: "fastify-plugin@npm:3.0.1" - checksum: 131ba0a388f777829c3fb0fd5b75cf057688ce6d0ca354fb1ebf829767a8c853b0825762b9185b5200097454df0ede2f3095da2efe1aa1b3736d07f194e6d374 - languageName: node - linkType: hard - "fastify-plugin@npm:^4.0.0": version: 4.5.1 resolution: "fastify-plugin@npm:4.5.1" @@ -2442,13 +2395,6 @@ __metadata: languageName: node linkType: hard -"luxon@npm:~3.3.0": - version: 3.3.0 - resolution: "luxon@npm:3.3.0" - checksum: 50cf17a0dc155c3dcacbeae8c0b7e80db425e0ba97b9cbdf12a7fc142d841ff1ab1560919f033af46240ed44e2f70c49f76e3422524c7fc8bb8d81ca47c66187 - languageName: node - linkType: hard - "make-error@npm:^1.1.1": version: 1.3.6 resolution: "make-error@npm:1.3.6" diff --git a/packages/helium-admin-cli/yarn.deploy.lock b/packages/helium-admin-cli/yarn.deploy.lock index 92d765de6..efe10fae3 100644 --- a/packages/helium-admin-cli/yarn.deploy.lock +++ b/packages/helium-admin-cli/yarn.deploy.lock @@ -260,7 +260,6 @@ __metadata: cors: ^2.8.5 dotenv: ^16.0.3 fastify: ^4.13.0 - fastify-cron: ^1.3.1 git-format-staged: ^2.1.3 ky: ^0.31.4 nodemon: ^2.0.20 @@ -881,15 +880,6 @@ __metadata: languageName: node linkType: hard -"@types/cron@npm:^2.0.0": - version: 2.4.0 - resolution: "@types/cron@npm:2.4.0" - dependencies: - cron: "npm:*" - checksum: c763e99a757ea76aee435948c25e0bdaf32ec44c69603088c73e8832df6b121e87932709925fe3e94777833ca30845c31df1167be54c330cf458d348059b9ffc - languageName: node - linkType: hard - "@types/crypto-js@npm:^4.1.1": version: 4.1.1 resolution: "@types/crypto-js@npm:4.1.1" @@ -944,13 +934,6 @@ __metadata: languageName: node linkType: hard -"@types/luxon@npm:~3.3.0": - version: 3.3.2 - resolution: "@types/luxon@npm:3.3.2" - checksum: b9111132720eae0269538872a5a496b29587ecfc8edc3b0ff7d269aa93a5ff00a131b23d1e9d1f12ec39f2c779ad21bd8d9f90b122c85a182771aabde7f676b8 - languageName: node - linkType: hard - "@types/mime@npm:*": version: 3.0.1 resolution: "@types/mime@npm:3.0.1" @@ -1704,16 +1687,6 @@ __metadata: languageName: node linkType: hard -"cron@npm:*, cron@npm:^2.0.0": - version: 2.4.3 - resolution: "cron@npm:2.4.3" - dependencies: - "@types/luxon": "npm:~3.3.0" - luxon: "npm:~3.3.0" - checksum: cb0ad49653b37ba125f8670ca92150ce515493512b1b8a5e08086d22bec9c54dc6d8926fcdb49ea5783f6699862ca5fdc532a440ce33c3228f9b3d565010db2f - languageName: node - linkType: hard - "cross-fetch@npm:^3.1.5": version: 3.1.8 resolution: "cross-fetch@npm:3.1.8" @@ -2012,26 +1985,6 @@ __metadata: languageName: node linkType: hard -"fastify-cron@npm:^1.3.1": - version: 1.3.1 - resolution: "fastify-cron@npm:1.3.1" - dependencies: - "@types/cron": "npm:^2.0.0" - cron: "npm:^2.0.0" - fastify-plugin: "npm:^3.0.0" - peerDependencies: - fastify: ^4.1.0 - checksum: 152cc6bfe9ebd347747d922533e49b9ee0528d1c22677858046615a7bbae07166af7fd4f126c00f0c6d380aca33da6fa91f572c24cb586107753b03ab16392f9 - languageName: node - linkType: hard - -"fastify-plugin@npm:^3.0.0": - version: 3.0.1 - resolution: "fastify-plugin@npm:3.0.1" - checksum: 131ba0a388f777829c3fb0fd5b75cf057688ce6d0ca354fb1ebf829767a8c853b0825762b9185b5200097454df0ede2f3095da2efe1aa1b3736d07f194e6d374 - languageName: node - linkType: hard - "fastify-plugin@npm:^4.0.0": version: 4.5.1 resolution: "fastify-plugin@npm:4.5.1" @@ -2732,13 +2685,6 @@ __metadata: languageName: node linkType: hard -"luxon@npm:~3.3.0": - version: 3.3.0 - resolution: "luxon@npm:3.3.0" - checksum: 50cf17a0dc155c3dcacbeae8c0b7e80db425e0ba97b9cbdf12a7fc142d841ff1ab1560919f033af46240ed44e2f70c49f76e3422524c7fc8bb8d81ca47c66187 - languageName: node - linkType: hard - "make-error@npm:^1.1.1": version: 1.3.6 resolution: "make-error@npm:1.3.6" diff --git a/packages/migration-service/yarn.deploy.lock b/packages/migration-service/yarn.deploy.lock index a66284794..926d51fc3 100644 --- a/packages/migration-service/yarn.deploy.lock +++ b/packages/migration-service/yarn.deploy.lock @@ -270,7 +270,6 @@ __metadata: cors: ^2.8.5 dotenv: ^16.0.3 fastify: ^4.13.0 - fastify-cron: ^1.3.1 git-format-staged: ^2.1.3 ky: ^0.31.4 nodemon: ^2.0.20 @@ -866,15 +865,6 @@ __metadata: languageName: node linkType: hard -"@types/cron@npm:^2.0.0": - version: 2.4.0 - resolution: "@types/cron@npm:2.4.0" - dependencies: - cron: "npm:*" - checksum: c763e99a757ea76aee435948c25e0bdaf32ec44c69603088c73e8832df6b121e87932709925fe3e94777833ca30845c31df1167be54c330cf458d348059b9ffc - languageName: node - linkType: hard - "@types/crypto-js@npm:^4.1.1": version: 4.1.1 resolution: "@types/crypto-js@npm:4.1.1" @@ -938,13 +928,6 @@ __metadata: languageName: node linkType: hard -"@types/luxon@npm:~3.3.0": - version: 3.3.2 - resolution: "@types/luxon@npm:3.3.2" - checksum: b9111132720eae0269538872a5a496b29587ecfc8edc3b0ff7d269aa93a5ff00a131b23d1e9d1f12ec39f2c779ad21bd8d9f90b122c85a182771aabde7f676b8 - languageName: node - linkType: hard - "@types/mime@npm:*": version: 3.0.1 resolution: "@types/mime@npm:3.0.1" @@ -1723,16 +1706,6 @@ __metadata: languageName: node linkType: hard -"cron@npm:*, cron@npm:^2.0.0": - version: 2.4.3 - resolution: "cron@npm:2.4.3" - dependencies: - "@types/luxon": "npm:~3.3.0" - luxon: "npm:~3.3.0" - checksum: cb0ad49653b37ba125f8670ca92150ce515493512b1b8a5e08086d22bec9c54dc6d8926fcdb49ea5783f6699862ca5fdc532a440ce33c3228f9b3d565010db2f - languageName: node - linkType: hard - "cross-fetch@npm:^3.1.5": version: 3.1.8 resolution: "cross-fetch@npm:3.1.8" @@ -2040,26 +2013,6 @@ __metadata: languageName: node linkType: hard -"fastify-cron@npm:^1.3.1": - version: 1.3.1 - resolution: "fastify-cron@npm:1.3.1" - dependencies: - "@types/cron": "npm:^2.0.0" - cron: "npm:^2.0.0" - fastify-plugin: "npm:^3.0.0" - peerDependencies: - fastify: ^4.1.0 - checksum: 152cc6bfe9ebd347747d922533e49b9ee0528d1c22677858046615a7bbae07166af7fd4f126c00f0c6d380aca33da6fa91f572c24cb586107753b03ab16392f9 - languageName: node - linkType: hard - -"fastify-plugin@npm:^3.0.0": - version: 3.0.1 - resolution: "fastify-plugin@npm:3.0.1" - checksum: 131ba0a388f777829c3fb0fd5b75cf057688ce6d0ca354fb1ebf829767a8c853b0825762b9185b5200097454df0ede2f3095da2efe1aa1b3736d07f194e6d374 - languageName: node - linkType: hard - "fastify-plugin@npm:^4.0.0": version: 4.5.1 resolution: "fastify-plugin@npm:4.5.1" @@ -2769,13 +2722,6 @@ __metadata: languageName: node linkType: hard -"luxon@npm:~3.3.0": - version: 3.3.0 - resolution: "luxon@npm:3.3.0" - checksum: 50cf17a0dc155c3dcacbeae8c0b7e80db425e0ba97b9cbdf12a7fc142d841ff1ab1560919f033af46240ed44e2f70c49f76e3422524c7fc8bb8d81ca47c66187 - languageName: node - linkType: hard - "make-error@npm:^1.1.1": version: 1.3.6 resolution: "make-error@npm:1.3.6" diff --git a/packages/monitor-service/package.json b/packages/monitor-service/package.json index af7269255..801127e84 100644 --- a/packages/monitor-service/package.json +++ b/packages/monitor-service/package.json @@ -41,6 +41,7 @@ "@helium/idls": "^0.6.10", "@helium/lazy-distributor-sdk": "^0.6.10", "@helium/lazy-transactions-sdk": "^0.6.10", + "@helium/price-oracle-sdk": "^0.6.10", "@helium/spl-utils": "^0.6.10", "@metaplex-foundation/mpl-bubblegum": "^3.0.0", "@metaplex-foundation/mpl-token-metadata": "^2.10.0", diff --git a/packages/monitor-service/src/index.ts b/packages/monitor-service/src/index.ts index 8be1b0e69..09ef63a97 100644 --- a/packages/monitor-service/src/index.ts +++ b/packages/monitor-service/src/index.ts @@ -1,46 +1,54 @@ -import { init as cbInit } from '@helium/circuit-breaker-sdk'; +import * as anchor from "@coral-xyz/anchor"; +import { init as cbInit } from "@helium/circuit-breaker-sdk"; +import { accountPayerKey } from "@helium/data-credits-sdk"; +import { + init as hemInit +} from "@helium/helium-entity-manager-sdk"; import { daoKey, init as hsdInit, - subDaoKey, - threadKey, -} from '@helium/helium-sub-daos-sdk'; -import { getAssociatedTokenAddressSync } from "@solana/spl-token" -import { init as hemInit, rewardableEntityConfigKey } from '@helium/helium-entity-manager-sdk'; -import { accountPayerKey } from '@helium/data-credits-sdk'; -import { CircuitBreaker } from '@helium/idls/lib/types/circuit_breaker'; -import { HeliumSubDaos } from '@helium/idls/lib/types/helium_sub_daos'; -import { HeliumEntityManager } from '@helium/idls/lib/types/helium_entity_manager'; -import * as anchor from '@coral-xyz/anchor'; -import fastify from 'fastify'; -import { HNT_MINT, MOBILE_MINT, IOT_MINT } from './env'; -import { register, totalRewardsGauge } from './metrics'; + subDaoKey +} from "@helium/helium-sub-daos-sdk"; +import { CircuitBreaker } from "@helium/idls/lib/types/circuit_breaker"; +import { HeliumEntityManager } from "@helium/idls/lib/types/helium_entity_manager"; +import { HeliumSubDaos } from "@helium/idls/lib/types/helium_sub_daos"; +import { PriceOracle } from "@helium/idls/lib/types/price_oracle"; +import { lazyDistributorKey } from "@helium/lazy-distributor-sdk"; +import { lazySignerKey } from "@helium/lazy-transactions-sdk"; +import { init as poInit } from "@helium/price-oracle-sdk"; +import { toNumber } from "@helium/spl-utils"; +import { getAssociatedTokenAddressSync } from "@solana/spl-token"; +import { PublicKey } from "@solana/web3.js"; +import { BN } from "bn.js"; +import fastify from "fastify"; +import { underscore } from "inflection"; +import { HNT_MINT, IOT_MINT, MOBILE_MINT } from "./env"; +import { + register, + totalRewardsGauge +} from "./metrics"; +import { Recipient, sequelize } from "./model"; import { monitiorAssociatedTokenBalance, monitorSolBalance, monitorTokenBalance, -} from './monitors/balance'; +} from "./monitors/balance"; import { monitorAccountCircuitBreaker, monitorMintCircuitBreaker, -} from './monitors/circuitBreaker'; -import { monitorSupply } from './monitors/supply'; -import { provider } from './solana'; -import { PublicKey } from '@solana/web3.js'; -import { lazySignerKey } from '@helium/lazy-transactions-sdk'; -import { underscore } from 'inflection'; -import { Recipient, sequelize } from './model'; -import { lazyDistributorKey } from '@helium/lazy-distributor-sdk'; -import { BN } from 'bn.js'; -import { toNumber } from '@helium/spl-utils'; -import { monitorVehnt } from './monitors/vehnt'; +} from "./monitors/circuitBreaker"; +import { monitorPriceOracle } from "./monitors/priceOracle"; +import { monitorSupply } from "./monitors/supply"; +import { monitorVehnt } from "./monitors/vehnt"; +import { provider } from "./solana"; let hemProgram: anchor.Program; let hsdProgram: anchor.Program; let cbProgram: anchor.Program; +let poProgram: anchor.Program; const server = fastify(); -server.get('/metrics', async (request, reply) => { +server.get("/metrics", async (request, reply) => { return register.metrics(); }); @@ -58,27 +66,39 @@ function debounce(func: any, wait: number = 10000) { async function setTotalRewards(mint: PublicKey) { const lazyDistributor = lazyDistributorKey(mint)[0].toBase58(); - const sum = (await Recipient.findAll({ - where: { - lazyDistributor, - }, - attributes: [ - [sequelize.fn("SUM", sequelize.col("total_rewards")), "totalRewards"], - ], - }))[0].totalRewards; - const sumActual = toNumber(new BN(sum), 6) - totalRewardsGauge.labels(mint.toBase58()).set(sumActual) + const sum = ( + await Recipient.findAll({ + where: { + lazyDistributor, + }, + attributes: [ + [sequelize.fn("SUM", sequelize.col("total_rewards")), "totalRewards"], + ], + }) + )[0].totalRewards; + const sumActual = toNumber(new BN(sum), 6); + totalRewardsGauge.labels(mint.toBase58()).set(sumActual); } async function run() { hemProgram = await hemInit(provider); hsdProgram = await hsdInit(provider); cbProgram = await cbInit(provider); + poProgram = await poInit(provider); const daoPk = daoKey(HNT_MINT)[0]; const dao = await hsdProgram.account.daoV0.fetch(daoPk); const mobileKey = subDaoKey(MOBILE_MINT)[0]; const iotKey = subDaoKey(IOT_MINT)[0]; + + server.listen({ port: 8082, host: "0.0.0.0" }, (err, address) => { + if (err) { + console.error(err); + process.exit(1); + } + console.log(`Server listening at ${address}`); + }); + const mobile = await hsdProgram.account.subDaoV0.fetch(mobileKey); const iot = await hsdProgram.account.subDaoV0.fetch(iotKey); const makers = await hemProgram.account.makerV0.all(); @@ -91,31 +111,43 @@ async function run() { const mobileMint = mobile.dntMint; const mobileTreasury = mobile.treasury; const mobileRewardsEscrow = mobile.rewardsEscrow; - - await Recipient.sync() - await monitorVehnt() - - await monitorSupply(hntMint, 'hnt'); - await monitorSupply(dcMint, 'dc'); - await monitorSupply(iotMint, 'iot'); - await monitorSupply(mobileMint, 'mobile'); - await monitorMintCircuitBreaker(cbProgram, hntMint, 'hnt_mint'); - await monitorMintCircuitBreaker(cbProgram, dcMint, 'dc_mint'); - await monitorMintCircuitBreaker(cbProgram, iotMint, 'iot_mint'); - await monitorMintCircuitBreaker(cbProgram, mobileMint, 'mobile_mint'); - - await monitorTokenBalance(iotTreasury, 'iot_treasury'); - await monitorTokenBalance(mobileTreasury, 'mobile_treasury'); - await setTotalRewards(IOT_MINT) - await setTotalRewards(MOBILE_MINT) + + await monitorPriceOracle(poProgram); + + await Recipient.sync(); + await monitorVehnt(); + + await monitorSupply(hntMint, "hnt"); + await monitorSupply(dcMint, "dc"); + await monitorSupply(iotMint, "iot"); + await monitorSupply(mobileMint, "mobile"); + await monitorMintCircuitBreaker(cbProgram, hntMint, "hnt_mint"); + await monitorMintCircuitBreaker(cbProgram, dcMint, "dc_mint"); + await monitorMintCircuitBreaker(cbProgram, iotMint, "iot_mint"); + await monitorMintCircuitBreaker(cbProgram, mobileMint, "mobile_mint"); + + await monitorTokenBalance(iotTreasury, "iot_treasury"); + await monitorTokenBalance(mobileTreasury, "mobile_treasury"); + await setTotalRewards(IOT_MINT); + await setTotalRewards(MOBILE_MINT); const resetMobileTotal = debounce(() => setTotalRewards(MOBILE_MINT)); const resetIotTotal = debounce(() => setTotalRewards(IOT_MINT)); - await monitorTokenBalance(iotRewardsEscrow, 'iot_rewards_escrow', false, async () => { - resetIotTotal(); - }); - await monitorTokenBalance(mobileRewardsEscrow, 'mobile_rewards_escrow', false, async () => { - resetMobileTotal(); - }); + await monitorTokenBalance( + iotRewardsEscrow, + "iot_rewards_escrow", + false, + async () => { + resetIotTotal(); + } + ); + await monitorTokenBalance( + mobileRewardsEscrow, + "mobile_rewards_escrow", + false, + async () => { + resetMobileTotal(); + } + ); await monitorTokenBalance( getAssociatedTokenAddressSync(dao.dcMint, iot.activeDeviceAuthority), "iot_active_device_oracle_dc" @@ -145,66 +177,58 @@ async function run() { dcMint, underscore(maker.account.name), true, - 'data-credits' + "data-credits" ); } await monitorSolBalance( new PublicKey( - process.env.CRON_KEY || 'cronjz7v2xsWdXr8BVz38ihi5DTWPihGZKuRr6vSPEU' + process.env.CRON_KEY || "cronjz7v2xsWdXr8BVz38ihi5DTWPihGZKuRr6vSPEU" ), - 'cron' + "cron" ); await monitorSolBalance( new PublicKey( - process.env.ORACLE_KEY || 'orc1TYY5L4B4ZWDEMayTqu99ikPM9bQo9fqzoaCPP5Q' + process.env.ORACLE_KEY || "orc1TYY5L4B4ZWDEMayTqu99ikPM9bQo9fqzoaCPP5Q" ), - 'oracle' + "oracle" ); await monitorSolBalance( new PublicKey( - process.env.MIGRATION_KEY || 'mgrArTL62g582wWV6iM4fwU1LKnbUikDN6akKJ76pzK' + process.env.MIGRATION_KEY || "mgrArTL62g582wWV6iM4fwU1LKnbUikDN6akKJ76pzK" ), - 'oracle' + "oracle" ); await monitorSolBalance( - lazySignerKey(process.env.LAZY_SIGNER || 'nJWGUMOK')[0], - 'lazy_signer' + lazySignerKey(process.env.LAZY_SIGNER || "nJWGUMOK")[0], + "lazy_signer" ); - await monitorSolBalance(mobile.dcBurnAuthority, 'mobile_dc_burn_authority'); + await monitorSolBalance(mobile.dcBurnAuthority, "mobile_dc_burn_authority"); - await monitorSolBalance(iot.dcBurnAuthority, 'iot_dc_burn_authority'); + await monitorSolBalance(iot.dcBurnAuthority, "iot_dc_burn_authority"); - await monitorSolBalance(accountPayerKey()[0], 'data_credits_account_payer'); + await monitorSolBalance(accountPayerKey()[0], "data_credits_account_payer"); const ep = provider.connection.rpcEndpoint; - const isLocalhost = ep.includes('127.0.0.1') || ep.includes('localhost'); + const isLocalhost = ep.includes("127.0.0.1") || ep.includes("localhost"); await monitorAccountCircuitBreaker( cbProgram, mobileTreasury, - 'mobile_treasury' + "mobile_treasury" ); - await monitorAccountCircuitBreaker(cbProgram, iotTreasury, 'iot_treasury'); + await monitorAccountCircuitBreaker(cbProgram, iotTreasury, "iot_treasury"); await monitorAccountCircuitBreaker( cbProgram, iotRewardsEscrow, - 'iot_rewards_escrow' + "iot_rewards_escrow" ); await monitorAccountCircuitBreaker( cbProgram, mobileRewardsEscrow, - 'mobile_rewards_escrow' + "mobile_rewards_escrow" ); - - server.listen({ port: 8082, host: '0.0.0.0' }, (err, address) => { - if (err) { - console.error(err); - process.exit(1); - } - console.log(`Server listening at ${address}`); - }); } run().catch((e) => { diff --git a/packages/monitor-service/src/metrics.ts b/packages/monitor-service/src/metrics.ts index ac211a154..c06156510 100644 --- a/packages/monitor-service/src/metrics.ts +++ b/packages/monitor-service/src/metrics.ts @@ -78,3 +78,17 @@ export const delegationsGauge = new client.Gauge({ }); register.registerMetric(delegationsGauge); +export const oraclePrice = new client.Gauge({ + name: "solana_price_oracle_price", + help: "The current price set by a price oracle wallet", + labelNames: ["oracle", "wallet"], +}); +register.registerMetric(oraclePrice); + +export const oracleTimeSinceSubmitted = new client.Gauge({ + name: "solana_price_oracle_time_since_submitted", + help: "The time since this oracle has submitted a price", + labelNames: ["oracle", "wallet"], +}); +register.registerMetric(oracleTimeSinceSubmitted); + diff --git a/packages/monitor-service/src/monitors/priceOracle.ts b/packages/monitor-service/src/monitors/priceOracle.ts new file mode 100644 index 000000000..6cba4c3cd --- /dev/null +++ b/packages/monitor-service/src/monitors/priceOracle.ts @@ -0,0 +1,56 @@ +import * as anchor from "@coral-xyz/anchor"; +import { watch } from "./watch"; +import { PublicKey } from "@solana/web3.js"; +import { PriceOracle } from "@helium/idls/lib/types/price_oracle"; +import { oraclePrice, oracleTimeSinceSubmitted } from "../metrics"; +import { monitorSolBalance } from "./balance"; + +const PRICE_ORACLES = [ + { + name: "iot", + key: new PublicKey("iortGU2NMgWc256XDBz2mQnmjPfKUMezJ4BWfayEZY3"), + }, + { + name: "mobile", + key: new PublicKey("iortGU2NMgWc256XDBz2mQnmjPfKUMezJ4BWfayEZY3"), + }, +]; + +type PriceOracleV0 = anchor.IdlAccounts["priceOracleV0"]; + +export async function monitorPriceOracle( + poProgram: anchor.Program +) { + for (const { name, key } of PRICE_ORACLES) { + const priceOracle = await poProgram.account.priceOracleV0.fetch(key); + watch(key, (raw) => { + if (raw) { + const { oracles } = poProgram.coder.accounts.decode( + "PriceOracleV0", + raw.data + ); + oracles.map((oracle) => { + oraclePrice + .labels({ + oracle: name, + wallet: oracle.authority.toBase58(), + }) + .set(oracle.lastSubmittedPrice?.toNumber() || 0); + oracleTimeSinceSubmitted + .labels({ + oracle: name, + wallet: oracle.authority.toBase58(), + }) + .set( + new Date().valueOf() / 1000 - + (oracle.lastSubmittedTimestamp?.toNumber() || 0) + ); + }); + } + }); + + priceOracle.oracles.map((oracle) => { + monitorSolBalance(oracle.authority, name + "_price_oracle"); + }); + } +} diff --git a/packages/monitor-service/src/monitors/watch.ts b/packages/monitor-service/src/monitors/watch.ts index ca6be46b1..fc24143db 100644 --- a/packages/monitor-service/src/monitors/watch.ts +++ b/packages/monitor-service/src/monitors/watch.ts @@ -17,9 +17,9 @@ export async function watch( } }); - // Force a requery every 30 seconds to ensure accuracy + // Force a requery every 5 minutes to ensure accuracy setInterval(async () => { // @ts-ignore onChange((await cache.search(account, undefined, false, true))?.account); - }, 30 * 1000); + }, 5 * 60 * 1000); } diff --git a/packages/monitor-service/tsconfig.json b/packages/monitor-service/tsconfig.json index cca417519..274e45a72 100644 --- a/packages/monitor-service/tsconfig.json +++ b/packages/monitor-service/tsconfig.json @@ -10,6 +10,9 @@ { "path": "../lazy-transactions-sdk" }, + { + "path": "../price-oracle-sdk" + }, { "path": "../lazy-distributor-sdk" }, diff --git a/packages/monitor-service/yarn.deploy.lock b/packages/monitor-service/yarn.deploy.lock index 8b6495e70..90a87d961 100644 --- a/packages/monitor-service/yarn.deploy.lock +++ b/packages/monitor-service/yarn.deploy.lock @@ -311,6 +311,7 @@ __metadata: "@helium/idls": ^0.6.10 "@helium/lazy-distributor-sdk": ^0.6.10 "@helium/lazy-transactions-sdk": ^0.6.10 + "@helium/price-oracle-sdk": ^0.6.10 "@helium/spl-utils": ^0.6.10 "@metaplex-foundation/mpl-bubblegum": ^3.0.0 "@metaplex-foundation/mpl-token-metadata": ^2.10.0 @@ -354,6 +355,21 @@ __metadata: languageName: unknown linkType: soft +"@helium/price-oracle-sdk@^0.6.10": + version: 0.0.0-use.local + resolution: "@helium/price-oracle-sdk@workspace:packages/price-oracle-sdk" + dependencies: + "@coral-xyz/anchor": ^0.28.0 + "@helium/idls": ^0.6.10 + bn.js: ^5.2.0 + bs58: ^4.0.1 + git-format-staged: ^2.1.3 + ts-loader: ^9.2.3 + ts-node: ^10.9.1 + typescript: ^5.2.2 + languageName: unknown + linkType: soft + "@helium/spl-utils@^0.6.10": version: 0.0.0-use.local resolution: "@helium/spl-utils@workspace:packages/spl-utils" diff --git a/packages/xnft-hotspot/yarn.deploy.lock b/packages/xnft-hotspot/yarn.deploy.lock index e51a9282d..607739241 100644 --- a/packages/xnft-hotspot/yarn.deploy.lock +++ b/packages/xnft-hotspot/yarn.deploy.lock @@ -404,7 +404,6 @@ __metadata: cors: ^2.8.5 dotenv: ^16.0.3 fastify: ^4.13.0 - fastify-cron: ^1.3.1 git-format-staged: ^2.1.3 ky: ^0.31.4 nodemon: ^2.0.20 @@ -2422,15 +2421,6 @@ __metadata: languageName: node linkType: hard -"@types/cron@npm:^2.0.0": - version: 2.4.0 - resolution: "@types/cron@npm:2.4.0" - dependencies: - cron: "npm:*" - checksum: c763e99a757ea76aee435948c25e0bdaf32ec44c69603088c73e8832df6b121e87932709925fe3e94777833ca30845c31df1167be54c330cf458d348059b9ffc - languageName: node - linkType: hard - "@types/crypto-js@npm:^4.1.1": version: 4.1.1 resolution: "@types/crypto-js@npm:4.1.1" @@ -2494,13 +2484,6 @@ __metadata: languageName: node linkType: hard -"@types/luxon@npm:~3.3.0": - version: 3.3.2 - resolution: "@types/luxon@npm:3.3.2" - checksum: b9111132720eae0269538872a5a496b29587ecfc8edc3b0ff7d269aa93a5ff00a131b23d1e9d1f12ec39f2c779ad21bd8d9f90b122c85a182771aabde7f676b8 - languageName: node - linkType: hard - "@types/mime@npm:*": version: 3.0.1 resolution: "@types/mime@npm:3.0.1" @@ -3616,16 +3599,6 @@ __metadata: languageName: node linkType: hard -"cron@npm:*, cron@npm:^2.0.0": - version: 2.4.3 - resolution: "cron@npm:2.4.3" - dependencies: - "@types/luxon": "npm:~3.3.0" - luxon: "npm:~3.3.0" - checksum: cb0ad49653b37ba125f8670ca92150ce515493512b1b8a5e08086d22bec9c54dc6d8926fcdb49ea5783f6699862ca5fdc532a440ce33c3228f9b3d565010db2f - languageName: node - linkType: hard - "cross-fetch@npm:3.0.6": version: 3.0.6 resolution: "cross-fetch@npm:3.0.6" @@ -4575,26 +4548,6 @@ __metadata: languageName: node linkType: hard -"fastify-cron@npm:^1.3.1": - version: 1.3.1 - resolution: "fastify-cron@npm:1.3.1" - dependencies: - "@types/cron": "npm:^2.0.0" - cron: "npm:^2.0.0" - fastify-plugin: "npm:^3.0.0" - peerDependencies: - fastify: ^4.1.0 - checksum: 152cc6bfe9ebd347747d922533e49b9ee0528d1c22677858046615a7bbae07166af7fd4f126c00f0c6d380aca33da6fa91f572c24cb586107753b03ab16392f9 - languageName: node - linkType: hard - -"fastify-plugin@npm:^3.0.0": - version: 3.0.1 - resolution: "fastify-plugin@npm:3.0.1" - checksum: 131ba0a388f777829c3fb0fd5b75cf057688ce6d0ca354fb1ebf829767a8c853b0825762b9185b5200097454df0ede2f3095da2efe1aa1b3736d07f194e6d374 - languageName: node - linkType: hard - "fastify-plugin@npm:^4.0.0": version: 4.5.1 resolution: "fastify-plugin@npm:4.5.1" @@ -5977,13 +5930,6 @@ __metadata: languageName: node linkType: hard -"luxon@npm:~3.3.0": - version: 3.3.0 - resolution: "luxon@npm:3.3.0" - checksum: 50cf17a0dc155c3dcacbeae8c0b7e80db425e0ba97b9cbdf12a7fc142d841ff1ab1560919f033af46240ed44e2f70c49f76e3422524c7fc8bb8d81ca47c66187 - languageName: node - linkType: hard - "make-dir@npm:^1.0.0, make-dir@npm:^1.2.0": version: 1.3.0 resolution: "make-dir@npm:1.3.0" diff --git a/yarn.lock b/yarn.lock index 2e79bdfe7..a9e21c539 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1179,7 +1179,6 @@ __metadata: cors: ^2.8.5 dotenv: ^16.0.3 fastify: ^4.13.0 - fastify-cron: ^1.3.1 git-format-staged: ^2.1.3 ky: ^0.31.4 nodemon: ^2.0.20 @@ -1642,6 +1641,7 @@ __metadata: "@helium/idls": ^0.6.10 "@helium/lazy-distributor-sdk": ^0.6.10 "@helium/lazy-transactions-sdk": ^0.6.10 + "@helium/price-oracle-sdk": ^0.6.10 "@helium/spl-utils": ^0.6.10 "@metaplex-foundation/mpl-bubblegum": ^3.0.0 "@metaplex-foundation/mpl-token-metadata": ^2.10.0