Initial commit
This commit is contained in:
commit
3474cdc45d
|
@ -0,0 +1,2 @@
|
|||
# Auto detect text files and perform LF normalization
|
||||
* text=auto
|
|
@ -0,0 +1,127 @@
|
|||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
lerna-debug.log*
|
||||
.pnpm-debug.log*
|
||||
|
||||
# Diagnostic reports (https://nodejs.org/api/report.html)
|
||||
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
|
||||
|
||||
# Runtime data
|
||||
pids
|
||||
*.pid
|
||||
*.seed
|
||||
*.pid.lock
|
||||
|
||||
# Directory for instrumented libs generated by jscoverage/JSCover
|
||||
lib-cov
|
||||
|
||||
# Coverage directory used by tools like istanbul
|
||||
coverage
|
||||
*.lcov
|
||||
|
||||
# nyc test coverage
|
||||
.nyc_output
|
||||
|
||||
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
|
||||
.grunt
|
||||
|
||||
# Bower dependency directory (https://bower.io/)
|
||||
bower_components
|
||||
|
||||
# node-waf configuration
|
||||
.lock-wscript
|
||||
|
||||
# Compiled binary addons (https://nodejs.org/api/addons.html)
|
||||
build/Release
|
||||
|
||||
# Dependency directories
|
||||
node_modules/
|
||||
jspm_packages/
|
||||
|
||||
# Snowpack dependency directory (https://snowpack.dev/)
|
||||
web_modules/
|
||||
|
||||
# TypeScript cache
|
||||
*.tsbuildinfo
|
||||
|
||||
# Optional npm cache directory
|
||||
.npm
|
||||
|
||||
# Optional eslint cache
|
||||
.eslintcache
|
||||
|
||||
# Optional stylelint cache
|
||||
.stylelintcache
|
||||
|
||||
# Microbundle cache
|
||||
.rpt2_cache/
|
||||
.rts2_cache_cjs/
|
||||
.rts2_cache_es/
|
||||
.rts2_cache_umd/
|
||||
|
||||
# Optional REPL history
|
||||
.node_repl_history
|
||||
|
||||
# Output of 'npm pack'
|
||||
*.tgz
|
||||
|
||||
# Yarn Integrity file
|
||||
.yarn-integrity
|
||||
|
||||
# dotenv environment variable files
|
||||
.env
|
||||
.env.development.local
|
||||
.env.test.local
|
||||
.env.production.local
|
||||
.env.local
|
||||
|
||||
# parcel-bundler cache (https://parceljs.org/)
|
||||
.cache
|
||||
.parcel-cache
|
||||
|
||||
# Next.js build output
|
||||
.next
|
||||
out
|
||||
|
||||
# Nuxt.js build / generate output
|
||||
.nuxt
|
||||
dist
|
||||
|
||||
# Gatsby files
|
||||
.cache/
|
||||
# Comment in the public line in if your project uses Gatsby and not Next.js
|
||||
# https://nextjs.org/blog/next-9-1#public-directory-support
|
||||
# public
|
||||
|
||||
# vuepress build output
|
||||
.vuepress/dist
|
||||
|
||||
# vuepress v2.x temp and cache directory
|
||||
.temp
|
||||
.cache
|
||||
|
||||
# Serverless directories
|
||||
.serverless/
|
||||
|
||||
# FuseBox cache
|
||||
.fusebox/
|
||||
|
||||
# DynamoDB Local files
|
||||
.dynamodb/
|
||||
|
||||
# TernJS port file
|
||||
.tern-port
|
||||
|
||||
# Stores VSCode versions used for testing VSCode extensions
|
||||
.vscode-test
|
||||
|
||||
# yarn v2
|
||||
.yarn/cache
|
||||
.yarn/unplugged
|
||||
.yarn/build-state.yml
|
||||
.yarn/install-state.gz
|
||||
.pnp.*
|
|
@ -0,0 +1,21 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) 2022 Rishi Panthee
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
|
@ -0,0 +1,155 @@
|
|||
const axios = require("axios")
|
||||
const logger = require("darla")
|
||||
const fs = require("fs")
|
||||
|
||||
logger.setLevel("console", "warn")
|
||||
|
||||
const ENGINE_NODE = "https://us.engine.rishipanthee.com/"
|
||||
const DISCORD_WEBHOOK_URL = ""
|
||||
const SYMBOL_TO_MONITOR = "SWAP.HIVE"
|
||||
|
||||
function getBlockEngine(blockNumber) {
|
||||
const query = { 'id': 0, jsonrpc: '2.0', method: 'getBlockInfo', params: { blockNumber: blockNumber } }
|
||||
let nextBlock = false
|
||||
axios.post(ENGINE_NODE + 'blockchain', query).then((res) => {
|
||||
if (res.data.result) {
|
||||
const block = res.data.result
|
||||
nextBlock = true
|
||||
logger.info(blockNumber)
|
||||
fs.writeFileSync("./state.json", JSON.stringify({ "lastParsedBlock": blockNumber }))
|
||||
parseBlockEngine(block)
|
||||
}
|
||||
}).finally(() => {
|
||||
if (nextBlock) {
|
||||
setTimeout(() => {
|
||||
getBlockEngine(blockNumber + 1)
|
||||
}, 0.5 * 1000)
|
||||
} else {
|
||||
setTimeout(() => {
|
||||
getBlockEngine(blockNumber)
|
||||
}, 1.5 * 1000)
|
||||
}
|
||||
}).catch((err) => {
|
||||
logger.error(`Unable to get latest Hive-Engine block. ${err}`)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
async function parseBlockEngine(block) {
|
||||
if (block.transactions.length !== 0) {
|
||||
for (const trx of block.transactions) {
|
||||
try {
|
||||
processTransaction(trx)
|
||||
} catch (err) {
|
||||
logger.error("Error noticed on a trx", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
async function processTransaction(trx) {
|
||||
if (trx.contract === "marketpools" && trx.action === "swapTokens") {
|
||||
const data = { quantityIn: "", symbolIn: "", userIn: "", quantityOut: "", symbolOut: "", userOut: "", feePaid: "", feeSymbol: "", trxID: "" }
|
||||
let logs = []
|
||||
try {
|
||||
logs = JSON.parse(trx.logs)
|
||||
if (!Array.isArray(logs.events)) {
|
||||
return
|
||||
}
|
||||
} catch (e) {
|
||||
logger.warn("Could not parse logs, most likely missing")
|
||||
logger.debug("The logs are : ", trx.logs)
|
||||
return
|
||||
}
|
||||
for (let event of logs.events) {
|
||||
if (event.event === "transferToContract") {
|
||||
data.quantityIn = event.data.quantity
|
||||
data.symbolIn = event.data.symbol
|
||||
data.userIn = event.data.from
|
||||
}
|
||||
|
||||
if (event.event === "transferFromContract") {
|
||||
data.quantityOut = event.data.quantity
|
||||
data.symbolOut = event.data.symbol
|
||||
data.userOut = event.data.to
|
||||
}
|
||||
|
||||
if (event.event === "swapTokens") {
|
||||
data.feePaid = event.data.fee.amount
|
||||
data.feeSymbol = event.data.fee.symbol
|
||||
}
|
||||
}
|
||||
|
||||
if (data.symbolIn !== SYMBOL_TO_MONITOR || data.symbolOut !== SYMBOL_TO_MONITOR) {
|
||||
return
|
||||
}
|
||||
|
||||
data.trxID = trx.transactionId
|
||||
|
||||
const send = {
|
||||
"content": null,
|
||||
"embeds": [
|
||||
{
|
||||
"title": `${SYMBOL_TO_MONITOR} was traded by ${data.userIn} `,
|
||||
"url": `https://he.dtools.dev/tx/${data.trxID}`,
|
||||
"color": 16711680,
|
||||
"fields": [
|
||||
{
|
||||
"name": "Input Tokens",
|
||||
"value": data.quantityIn + " " + data.symbolIn
|
||||
},
|
||||
{
|
||||
"name": "Output Token",
|
||||
"value": data.quantityOut + " " + data.symbolOut
|
||||
},
|
||||
{
|
||||
"name": "Fees",
|
||||
"value": data.feePaid + " " + data.feeSymbol
|
||||
}
|
||||
],
|
||||
"author": {
|
||||
"name": `Noticed activity on ${data.symbolIn}:${data.symbolOut} pool`,
|
||||
"icon_url": `https://images.hive.blog/u/${data.userIn}/avatar`
|
||||
},
|
||||
"footer": {
|
||||
"text": "Trade successfully completed.",
|
||||
"icon_url": "https://ipfspublic.rishipanthee.com/ipfs/QmWRqmJ1zmk5bYGoB6jntJzh3qt3mxcZhoByeZAgFjXD2W"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
try {
|
||||
await axios.post(DISCORD_WEBHOOK_URL, send)
|
||||
} catch (err) {
|
||||
logger.error('Error posting to discord', err)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
async function getStartStreamBlockEngine() {
|
||||
return new Promise((resolve, reject) => {
|
||||
const currentState = JSON.parse(fs.readFileSync("./state.json").toString())
|
||||
if (currentState.lastParsedBlock && currentState.lastParsedBlock != -1) {
|
||||
return resolve(currentState.lastParsedBlock)
|
||||
}
|
||||
const query = { 'jsonrpc': '2.0', 'method': 'getLatestBlockInfo', 'id': 0 }
|
||||
axios.post(ENGINE_NODE + 'blockchain', query).then((result) => {
|
||||
return resolve(result.data.result.blockNumber)
|
||||
}).catch((err) => {
|
||||
return reject(err)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
async function startStreaming() {
|
||||
const startBlockHE = await getStartStreamBlockEngine()
|
||||
getBlockEngine(startBlockHE)
|
||||
}
|
||||
|
||||
|
||||
startStreaming()
|
|
@ -0,0 +1,172 @@
|
|||
{
|
||||
"name": "kittybot",
|
||||
"version": "1.0.0",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "kittybot",
|
||||
"version": "1.0.0",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"axios": "^0.27.2",
|
||||
"darla": "^1.1.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=18.0.0",
|
||||
"npm": ">=8.19.0"
|
||||
}
|
||||
},
|
||||
"node_modules/asynckit": {
|
||||
"version": "0.4.0",
|
||||
"resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz",
|
||||
"integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q=="
|
||||
},
|
||||
"node_modules/axios": {
|
||||
"version": "0.27.2",
|
||||
"resolved": "https://registry.npmjs.org/axios/-/axios-0.27.2.tgz",
|
||||
"integrity": "sha512-t+yRIyySRTp/wua5xEr+z1q60QmLq8ABsS5O9Me1AsE5dfKqgnCFzwiCZZ/cGNd1lq4/7akDWMxdhVlucjmnOQ==",
|
||||
"dependencies": {
|
||||
"follow-redirects": "^1.14.9",
|
||||
"form-data": "^4.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/combined-stream": {
|
||||
"version": "1.0.8",
|
||||
"resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz",
|
||||
"integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==",
|
||||
"dependencies": {
|
||||
"delayed-stream": "~1.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/darla": {
|
||||
"version": "1.1.1",
|
||||
"resolved": "https://registry.npmjs.org/darla/-/darla-1.1.1.tgz",
|
||||
"integrity": "sha512-FeZAcw12uBFM3PiJNE46sj32aysuMapC9qxh26NwtdHVs7bf0tGazVHZOd+k0KcFPoutcZ2PE6gYzZQgu8EJzw=="
|
||||
},
|
||||
"node_modules/delayed-stream": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz",
|
||||
"integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==",
|
||||
"engines": {
|
||||
"node": ">=0.4.0"
|
||||
}
|
||||
},
|
||||
"node_modules/follow-redirects": {
|
||||
"version": "1.15.2",
|
||||
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.2.tgz",
|
||||
"integrity": "sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA==",
|
||||
"funding": [
|
||||
{
|
||||
"type": "individual",
|
||||
"url": "https://github.com/sponsors/RubenVerborgh"
|
||||
}
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=4.0"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"debug": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/form-data": {
|
||||
"version": "4.0.0",
|
||||
"resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz",
|
||||
"integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==",
|
||||
"dependencies": {
|
||||
"asynckit": "^0.4.0",
|
||||
"combined-stream": "^1.0.8",
|
||||
"mime-types": "^2.1.12"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 6"
|
||||
}
|
||||
},
|
||||
"node_modules/mime-db": {
|
||||
"version": "1.52.0",
|
||||
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz",
|
||||
"integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==",
|
||||
"engines": {
|
||||
"node": ">= 0.6"
|
||||
}
|
||||
},
|
||||
"node_modules/mime-types": {
|
||||
"version": "2.1.35",
|
||||
"resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz",
|
||||
"integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==",
|
||||
"dependencies": {
|
||||
"mime-db": "1.52.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.6"
|
||||
}
|
||||
}
|
||||
},
|
||||
"dependencies": {
|
||||
"asynckit": {
|
||||
"version": "0.4.0",
|
||||
"resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz",
|
||||
"integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q=="
|
||||
},
|
||||
"axios": {
|
||||
"version": "0.27.2",
|
||||
"resolved": "https://registry.npmjs.org/axios/-/axios-0.27.2.tgz",
|
||||
"integrity": "sha512-t+yRIyySRTp/wua5xEr+z1q60QmLq8ABsS5O9Me1AsE5dfKqgnCFzwiCZZ/cGNd1lq4/7akDWMxdhVlucjmnOQ==",
|
||||
"requires": {
|
||||
"follow-redirects": "^1.14.9",
|
||||
"form-data": "^4.0.0"
|
||||
}
|
||||
},
|
||||
"combined-stream": {
|
||||
"version": "1.0.8",
|
||||
"resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz",
|
||||
"integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==",
|
||||
"requires": {
|
||||
"delayed-stream": "~1.0.0"
|
||||
}
|
||||
},
|
||||
"darla": {
|
||||
"version": "1.1.1",
|
||||
"resolved": "https://registry.npmjs.org/darla/-/darla-1.1.1.tgz",
|
||||
"integrity": "sha512-FeZAcw12uBFM3PiJNE46sj32aysuMapC9qxh26NwtdHVs7bf0tGazVHZOd+k0KcFPoutcZ2PE6gYzZQgu8EJzw=="
|
||||
},
|
||||
"delayed-stream": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz",
|
||||
"integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ=="
|
||||
},
|
||||
"follow-redirects": {
|
||||
"version": "1.15.2",
|
||||
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.2.tgz",
|
||||
"integrity": "sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA=="
|
||||
},
|
||||
"form-data": {
|
||||
"version": "4.0.0",
|
||||
"resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz",
|
||||
"integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==",
|
||||
"requires": {
|
||||
"asynckit": "^0.4.0",
|
||||
"combined-stream": "^1.0.8",
|
||||
"mime-types": "^2.1.12"
|
||||
}
|
||||
},
|
||||
"mime-db": {
|
||||
"version": "1.52.0",
|
||||
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz",
|
||||
"integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg=="
|
||||
},
|
||||
"mime-types": {
|
||||
"version": "2.1.35",
|
||||
"resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz",
|
||||
"integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==",
|
||||
"requires": {
|
||||
"mime-db": "1.52.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
{
|
||||
"name": "enginePoolMonitor",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=18.0.0",
|
||||
"npm": ">=8.19.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"axios": "^0.27.2",
|
||||
"darla": "^1.1.1"
|
||||
}
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
{"lastParsedBlock":-1}
|
Loading…
Reference in New Issue