remove commented code
This commit is contained in:
parent
d6336f26c9
commit
6386cd58c0
15
README.md
15
README.md
|
@ -4,24 +4,21 @@ Backend logic for the mango alerts provider
|
|||
|
||||
## Usage
|
||||
|
||||
Run ```yarn``` to install dependencies
|
||||
Run `yarn` to install dependencies
|
||||
|
||||
```bash
|
||||
yarn
|
||||
```
|
||||
|
||||
An example ```.env``` file -
|
||||
An example `.env` file -
|
||||
|
||||
```
|
||||
DB_USER=<DB_USER>
|
||||
DB_PASS=<DB_PASS>
|
||||
DB_HOSTS=<DB_HOST>
|
||||
DB_CLUSTER=<DB_CLUSTER>
|
||||
DB=<DB>
|
||||
DB_OPTIONS=<DB_OPTIONS>
|
||||
PORT=3010
|
||||
TWILIO_ACCOUNT_SID=<TWILIO_ACCOUNT_SID>
|
||||
TWILIO_AUTH_TOKEN=<TWILIO_AUTH_TOKEN>
|
||||
TWILIO_PHONE_NUMBER=<TWILIO_PHONE_NUMBER>
|
||||
MAIL_USER=<MAIL_USER>
|
||||
MAIL_PASS=<MAIL_PASS>
|
||||
TG_TOKEN=<TG_TOKEN>
|
||||
MAILJET_KEY=<MAILJET_KEY>
|
||||
MAILJET_SECRET=<MAILJET_SECRET>
|
||||
```
|
||||
|
|
|
@ -10,13 +10,7 @@ export default {
|
|||
db: process.env.DB || "",
|
||||
port: process.env.PORT || 3000,
|
||||
|
||||
twilioSid: process.env.TWILIO_ACCOUNT_SID || "",
|
||||
twilioToken: process.env.TWILIO_AUTH_TOKEN || "",
|
||||
twilioNumber: process.env.TWILIO_PHONE_NUMBER || "",
|
||||
|
||||
mailUser: process.env.MAIL_USER || "",
|
||||
mailJetKey: process.env.MAILJET_KEY || "",
|
||||
mailJetSecret: process.env.MAILJET_SECRET || "",
|
||||
// tgToken: process.env.TG_TOKEN || '',
|
||||
// discordWebhook: process.env.DISCORD_WEBHOOK || ''
|
||||
}
|
||||
|
|
27
src/index.ts
27
src/index.ts
|
@ -9,24 +9,13 @@ import { MongoClient, ObjectId } from "mongodb"
|
|||
import {
|
||||
Cluster,
|
||||
Config,
|
||||
GroupConfig,
|
||||
MangoClient,
|
||||
MangoAccount,
|
||||
IDS,
|
||||
} from "@blockworks-foundation/mango-client"
|
||||
import { Commitment, Connection, PublicKey } from "@solana/web3.js"
|
||||
|
||||
import { UserError } from "./errors"
|
||||
// import { sendLogsToDiscord } from "./logger"
|
||||
import {
|
||||
// initiateTelegramBot,
|
||||
// generateTelegramCode,
|
||||
validateMangoAccount,
|
||||
// validatePhoneNumber,
|
||||
validateEmail,
|
||||
reduceMangoGroups,
|
||||
sendAlert,
|
||||
} from "./utils"
|
||||
import { validateMangoAccount, validateEmail, sendAlert } from "./utils"
|
||||
import config from "./environment"
|
||||
|
||||
const MESSAGE = "Your health ratio is at or below @ratio@% \n"
|
||||
|
@ -34,8 +23,6 @@ const MESSAGE = "Your health ratio is at or below @ratio@% \n"
|
|||
const app = new Koa()
|
||||
const router = new Router()
|
||||
|
||||
// const rpcUrl = "https://mango.rpcpool.com/946ef7337da3f5b8d3e4a34e7f88"
|
||||
|
||||
const clientConfig = new Config(IDS)
|
||||
|
||||
const cluster = (process.env.CLUSTER || "mainnet") as Cluster
|
||||
|
@ -46,7 +33,6 @@ if (!groupIds) {
|
|||
}
|
||||
|
||||
const mangoProgramId = groupIds.mangoProgramId
|
||||
// const mangoGroupKey = groupIds.publicKey
|
||||
|
||||
const connection = new Connection(
|
||||
process.env.ENDPOINT_URL || clientConfig.cluster_urls[cluster],
|
||||
|
@ -68,8 +54,6 @@ app.use(
|
|||
)
|
||||
)
|
||||
|
||||
// initiateTelegramBot()
|
||||
|
||||
router.post("/alerts", async (ctx, next) => {
|
||||
try {
|
||||
const alert: any = ctx.request.body
|
||||
|
@ -202,14 +186,9 @@ const runCron = async () => {
|
|||
.collection("alerts")
|
||||
.find({ open: true })
|
||||
.toArray()
|
||||
|
||||
console.log(alerts)
|
||||
// const uniqueMangoGroupPks: string[] = [
|
||||
// ...new Set(alerts.map((alert) => alert.mangoGroupPk)),
|
||||
// ]
|
||||
// const mangoGroups: any = await reduceMangoGroups(
|
||||
// client,
|
||||
// uniqueMangoGroupPks
|
||||
// )
|
||||
|
||||
alerts.forEach(async (alert) => {
|
||||
handleAlert(alert, db)
|
||||
})
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import winston from "winston"
|
||||
import DiscordTransport from "winston-discord-transport"
|
||||
import config from "./environment"
|
||||
// import winston from "winston"
|
||||
// import DiscordTransport from "winston-discord-transport"
|
||||
// import config from "./environment"
|
||||
|
||||
// const logger = winston.createLogger({
|
||||
// transports: [
|
||||
|
|
81
src/utils.ts
81
src/utils.ts
|
@ -1,6 +1,3 @@
|
|||
// import { Twilio } from "twilio"
|
||||
// import * as mailjetTransport from 'nodemailer-mailjet-transport'
|
||||
// import * as TelegramBot from "node-telegram-bot-api"
|
||||
// import { MongoClient } from "mongodb"
|
||||
import * as nodemailer from "nodemailer"
|
||||
import * as EmailValidator from "email-validator"
|
||||
|
@ -39,18 +36,6 @@ export const validateMangoAccount = (client: MangoClient, alert: any) => {
|
|||
})
|
||||
}
|
||||
|
||||
// export const validatePhoneNumber = (phoneNumber: string) => {
|
||||
// return new Promise<void>((resolve, reject) => {
|
||||
// twilioClient.lookups.phoneNumbers(phoneNumber).fetch((e, _) => {
|
||||
// if (e) {
|
||||
// reject(new UserError("The entered phone number is incorrect"))
|
||||
// } else {
|
||||
// resolve()
|
||||
// }
|
||||
// })
|
||||
// })
|
||||
// }
|
||||
|
||||
export const validateEmail = (email: string) => {
|
||||
if (!EmailValidator.validate(email)) {
|
||||
throw new UserError("The entered email is incorrect")
|
||||
|
@ -58,19 +43,6 @@ export const validateEmail = (email: string) => {
|
|||
return
|
||||
}
|
||||
|
||||
// const sendSms = (phoneNumber: string, message: string) => {
|
||||
// return new Promise<void>((resolve, reject) => {
|
||||
// twilioClient.messages
|
||||
// .create({
|
||||
// from: config.twilioNumber,
|
||||
// to: phoneNumber,
|
||||
// body: message,
|
||||
// })
|
||||
// .then((_) => resolve())
|
||||
// .catch((e) => reject(e))
|
||||
// })
|
||||
// }
|
||||
|
||||
const sendEmail = async (email: string, message: string) => {
|
||||
const transport = nodemailer.createTransport(
|
||||
mailjetTransport({
|
||||
|
@ -101,58 +73,5 @@ export const sendAlert = async (alert: any, message: string) => {
|
|||
const email = alert.email
|
||||
sendEmail(email, message)
|
||||
}
|
||||
// else if (alert.alertProvider == "sms") {
|
||||
// const phoneNumber = `+${alert.phoneNumber.code}${alert.phoneNumber.phone}
|
||||
// await sendSms(phoneNumber, message)
|
||||
// }
|
||||
// else if (alert.alertProvider == 'tg') {
|
||||
// if (!alert.tgChatId) return false;
|
||||
// bot.sendMessage(alert.tgChatId, message);
|
||||
// }
|
||||
return true
|
||||
}
|
||||
|
||||
export const reduceMangoGroups = async (
|
||||
client: MangoClient,
|
||||
// connection: Connection,
|
||||
// mangoProgramId: PublicKey,
|
||||
mangoGroupPks: string[]
|
||||
) => {
|
||||
const mangoGroups: any = {}
|
||||
for (let mangoGroupPk of mangoGroupPks) {
|
||||
const mangoGroup = await client.getMangoGroup(new PublicKey(mangoGroupPk))
|
||||
const mangoAccounts = await client.getAllMangoAccounts(mangoGroup)
|
||||
mangoGroups[mangoGroupPk] = {
|
||||
mangoGroup,
|
||||
mangoAccounts,
|
||||
// prices: await mangoGroup.getPrices(connection),
|
||||
}
|
||||
}
|
||||
return mangoGroups
|
||||
}
|
||||
|
||||
// export const initiateTelegramBot = () => {
|
||||
// bot.on('message', async (message: any) => {
|
||||
// const mongoConnection = await MongoClient.connect(config.dbConnectionString, { useUnifiedTopology: true });
|
||||
// const db = mongoConnection.db(config.db);
|
||||
// const tgCode = message.text;
|
||||
// const alert = await db.collection('alerts').findOne({tgCode});
|
||||
// if (alert) {
|
||||
// await db.collection('alerts').updateOne({ tgCode }, {'$set': { tgChatId: message.chat.id } } );
|
||||
// bot.sendMessage(message.chat.id, 'Thanks, You have successfully claimed your alert\nYou can now close the dialogue on website');
|
||||
// } else {
|
||||
// bot.sendMessage(message.chat.id, 'Sorry, this code is either invalid or expired');
|
||||
// }
|
||||
// mongoConnection.close();
|
||||
// });
|
||||
// }
|
||||
|
||||
// export const generateTelegramCode = () => {
|
||||
// var text = ""
|
||||
// var possible =
|
||||
// "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
|
||||
// for (let i = 0; i < 5; i++) {
|
||||
// text += possible.charAt(Math.floor(Math.random() * possible.length))
|
||||
// }
|
||||
// return text
|
||||
// }
|
||||
|
|
Loading…
Reference in New Issue