-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement saber monitoring service (#1)
* Bootstrap repo * Add additional deps: quarry and axios * Init gauge sdk + get gaugemeister * Add extraction of relative data and rewards/day * Implement whale monitor * Implement cron reports * Use monitor version form npm * Fix typo * Remove redundant console log * Decrease poll interval to a single minute * Move rpc url to env vars * Add docker ignore * Add logging * Fix deployment yaml * Fix epoch in notification * Fix total share calculation * Fix ordering of pools * Send stats 2 times per day Co-authored-by: Alexey Tsymbal <[email protected]>
- Loading branch information
Showing
25 changed files
with
6,592 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
Dockerfile | ||
.dockerignore | ||
node_modules | ||
dist | ||
npm-debug.log | ||
env-dev-fb-admin-key.json | ||
*.env | ||
*.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
module.exports = { | ||
parser: '@typescript-eslint/parser', | ||
parserOptions: { | ||
project: 'tsconfig.json', | ||
sourceType: 'module', | ||
}, | ||
plugins: ['@typescript-eslint/eslint-plugin'], | ||
extends: [ | ||
'plugin:@typescript-eslint/recommended', | ||
'plugin:prettier/recommended', | ||
], | ||
root: true, | ||
env: { | ||
node: true, | ||
jest: true, | ||
}, | ||
ignorePatterns: ['.eslintrc.js'], | ||
rules: { | ||
'@typescript-eslint/interface-name-prefix': 'off', | ||
'@typescript-eslint/explicit-function-return-type': 'off', | ||
'@typescript-eslint/explicit-module-boundary-types': 'off', | ||
'@typescript-eslint/no-explicit-any': 'off', | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# compiled output | ||
/dist | ||
/node_modules | ||
|
||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
pnpm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
lerna-debug.log* | ||
|
||
# OS | ||
.DS_Store | ||
|
||
# Tests | ||
/coverage | ||
/.nyc_output | ||
|
||
# IDEs and editors | ||
/.idea | ||
.project | ||
.classpath | ||
.c9/ | ||
*.launch | ||
.settings/ | ||
*.sublime-workspace | ||
|
||
# IDE - VSCode | ||
.vscode/* | ||
!.vscode/settings.json | ||
!.vscode/tasks.json | ||
!.vscode/launch.json | ||
!.vscode/extensions.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"singleQuote": true, | ||
"trailingComma": "all" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
FROM node:16-alpine | ||
|
||
WORKDIR /app | ||
|
||
RUN npm i -g rimraf | ||
|
||
COPY package.json yarn.lock ./ | ||
RUN yarn | ||
|
||
COPY . ./ | ||
RUN yarn build | ||
|
||
EXPOSE 8080 | ||
CMD [ "node", "dist/main.js" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,57 @@ | ||
# saber-monitoring-service | ||
# Saber monitoring service | ||
|
||
A reference implementation of a service running `@dialectlabs/monitor` for saber wars. | ||
See https://github.com/dialectlabs/monitor for details on the notifications module. | ||
|
||
## Development | ||
|
||
### Prerequisites | ||
|
||
- Git | ||
- Yarn (<2) | ||
- Nodejs (>=16.10.0 <17) | ||
|
||
### Getting started with monitor development in this repo | ||
|
||
#### Install dependencies | ||
|
||
**npm:** | ||
|
||
```shell | ||
npm install | ||
``` | ||
|
||
**yarn:** | ||
|
||
```shell | ||
yarn | ||
``` | ||
|
||
### Running locally | ||
|
||
```shell | ||
MAINNET_RPC_URL=rpcUrl \ | ||
TWITTER_APP_KEY=appKey \ | ||
TWITTER_APP_SECRET=appSecret \ | ||
TWITTER_ACCESS_TOKEN=accessToken \ | ||
TWITTER_ACCESS_SECRET=accessSecret \ | ||
WHALE_MONITOR_THRESHOLD=5000 \ | ||
yarn start:dev | ||
``` | ||
|
||
### Containerization | ||
|
||
#### Build image (macOS) | ||
|
||
```shell | ||
brew install jq | ||
./docker-build.sh | ||
``` | ||
|
||
#### Publish image | ||
|
||
```shell | ||
brew install jq | ||
docker login | ||
./docker-publish.sh | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
annotations: | ||
deployment.kubernetes.io/revision: "16" | ||
labels: | ||
app: saber-monitoring-service | ||
name: saber-monitoring-service | ||
namespace: default | ||
resourceVersion: "65918483" | ||
spec: | ||
progressDeadlineSeconds: 600 | ||
replicas: 1 | ||
revisionHistoryLimit: 10 | ||
selector: | ||
matchLabels: | ||
app: saber-monitoring-service | ||
strategy: | ||
rollingUpdate: | ||
maxSurge: 25% | ||
maxUnavailable: 25% | ||
type: RollingUpdate | ||
template: | ||
metadata: | ||
creationTimestamp: null | ||
labels: | ||
app: saber-monitoring-service | ||
spec: | ||
containers: | ||
- env: | ||
- name: WHALE_MONITOR_THRESHOLD | ||
value: "4000000" | ||
- name: MAINNET_RPC_URL | ||
valueFrom: | ||
secretKeyRef: | ||
key: MAINNET_RPC_URL | ||
name: env-vars | ||
- name: TWITTER_APP_KEY | ||
valueFrom: | ||
secretKeyRef: | ||
key: TWITTER_APP_KEY | ||
name: env-vars | ||
- name: TWITTER_APP_SECRET | ||
valueFrom: | ||
secretKeyRef: | ||
key: TWITTER_APP_SECRET | ||
name: env-vars | ||
- name: TWITTER_ACCESS_TOKEN | ||
valueFrom: | ||
secretKeyRef: | ||
key: TWITTER_ACCESS_TOKEN | ||
name: env-vars | ||
- name: TWITTER_ACCESS_SECRET | ||
valueFrom: | ||
secretKeyRef: | ||
key: TWITTER_ACCESS_SECRET | ||
name: env-vars | ||
image: dialectlab/saber-monitoring-service:0.0.1 | ||
imagePullPolicy: Always | ||
name: saber-monitoring-service | ||
resources: {} | ||
terminationMessagePath: /dev/termination-log | ||
terminationMessagePolicy: File | ||
dnsPolicy: ClusterFirst | ||
imagePullSecrets: | ||
- name: regcred | ||
restartPolicy: Always | ||
schedulerName: default-scheduler | ||
securityContext: {} | ||
terminationGracePeriodSeconds: 30 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package_version=$(jq -r .version package.json) | ||
|
||
docker build --platform linux/amd64 \ | ||
-t dialectlab/saber-monitoring-service:"$package_version" \ | ||
-t dialectlab/saber-monitoring-service:latest . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package_version=$(jq -r .version package.json) | ||
|
||
docker push dialectlab/saber-monitoring-service:"$package_version" | ||
docker push dialectlab/saber-monitoring-service:latest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { getWarsInfo } from '../src/saber-wars-api/saber-wars-api'; | ||
|
||
async function run() { | ||
const warsInfo = await getWarsInfo(); | ||
warsInfo.poolsInfo.forEach( | ||
({ | ||
name, | ||
currentEpochRelativeShare, | ||
currentEpochAbsoluteShare, | ||
currentEpochRewardsPerDay, | ||
nextEpochRelativeShare, | ||
nextEpochAbsoluteShare, | ||
nextEpochRewardsPerDay, | ||
}) => | ||
console.log( | ||
name, | ||
`current share: ${currentEpochRelativeShare.toFixed( | ||
2, | ||
)}% (${currentEpochAbsoluteShare.toFixed( | ||
3, | ||
)}): ${currentEpochRewardsPerDay.toFixed(0)} SBR/day`, | ||
`next share: ${nextEpochRelativeShare.toFixed( | ||
2, | ||
)}% (${nextEpochAbsoluteShare.toFixed( | ||
3, | ||
)}): ${nextEpochRewardsPerDay.toFixed(0)} SBR/day`, | ||
), | ||
); | ||
} | ||
|
||
run(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { TwitterNotificationSink } from '../src/monitor/twitter-notification-sink'; | ||
|
||
const twitterNotificationSink = new TwitterNotificationSink(); | ||
twitterNotificationSink.push({ | ||
message: 'test', | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"collection": "@nestjs/schematics", | ||
"sourceRoot": "src" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
{ | ||
"name": "saber-monitoring-service", | ||
"version": "0.0.1", | ||
"description": "", | ||
"author": "dialectlabs", | ||
"private": true, | ||
"license": "UNLICENSED", | ||
"scripts": { | ||
"prebuild": "rimraf dist", | ||
"build": "nest build", | ||
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"", | ||
"start": "nest start", | ||
"start:dev": "nest start --watch", | ||
"start:debug": "nest start --debug --watch", | ||
"start:prod": "node dist/main", | ||
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix", | ||
"test": "jest", | ||
"test:watch": "jest --watch", | ||
"test:cov": "jest --coverage", | ||
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand", | ||
"test:e2e": "jest --config ./test/jest-e2e.json" | ||
}, | ||
"dependencies": { | ||
"@dialectlabs/monitor": "0.1.22", | ||
"@gokiprotocol/client": "^0.6.1", | ||
"@nestjs/common": "^8.0.0", | ||
"@nestjs/core": "^8.0.0", | ||
"@nestjs/platform-express": "^8.0.0", | ||
"@nestjs/schedule": "^1.0.2", | ||
"@project-serum/anchor": "^0.21.0", | ||
"@quarryprotocol/gauge": "^0.2.2", | ||
"@quarryprotocol/quarry-sdk": "^2.0.1", | ||
"@saberhq/anchor-contrib": "^1.12.45", | ||
"@saberhq/solana-contrib": "^1.12.45", | ||
"@saberhq/token-utils": "^1.12.45", | ||
"@solana/web3.js": "^1.34.0", | ||
"@tribecahq/tribeca-sdk": "^0.4.2", | ||
"axios": "^0.26.0", | ||
"bn.js": "^5.2.0", | ||
"jsbi": "^4.1.0", | ||
"luxon": "^2.3.0", | ||
"reflect-metadata": "^0.1.13", | ||
"rimraf": "^3.0.2", | ||
"rxjs": "^7.2.0", | ||
"twitter-api-v2": "^1.11.0" | ||
}, | ||
"devDependencies": { | ||
"@nestjs/cli": "^8.0.0", | ||
"@nestjs/schematics": "^8.0.0", | ||
"@nestjs/testing": "^8.0.0", | ||
"@types/axios": "^0.14.0", | ||
"@types/bn.js": "^5.1.0", | ||
"@types/cron": "^1.7.3", | ||
"@types/express": "^4.17.13", | ||
"@types/jest": "27.4.0", | ||
"@types/luxon": "^2.0.9", | ||
"@types/node": "^16.0.0", | ||
"@types/supertest": "^2.0.11", | ||
"@typescript-eslint/eslint-plugin": "^5.0.0", | ||
"@typescript-eslint/parser": "^5.0.0", | ||
"eslint": "^8.0.1", | ||
"eslint-config-prettier": "^8.3.0", | ||
"eslint-plugin-prettier": "^4.0.0", | ||
"jest": "^27.2.5", | ||
"prettier": "^2.3.2", | ||
"source-map-support": "^0.5.20", | ||
"supertest": "^6.1.3", | ||
"ts-jest": "^27.0.3", | ||
"ts-loader": "^9.2.3", | ||
"ts-node": "^10.0.0", | ||
"tsconfig-paths": "^3.10.1", | ||
"typescript": "^4.3.5" | ||
}, | ||
"jest": { | ||
"moduleFileExtensions": [ | ||
"js", | ||
"json", | ||
"ts" | ||
], | ||
"rootDir": "src", | ||
"testRegex": ".*\\.spec\\.ts$", | ||
"transform": { | ||
"^.+\\.(t|j)s$": "ts-jest" | ||
}, | ||
"collectCoverageFrom": [ | ||
"**/*.(t|j)s" | ||
], | ||
"coverageDirectory": "../coverage", | ||
"testEnvironment": "node" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { SaberMonitoringService } from './monitor/saber-monitoring-service'; | ||
import { ScheduleModule } from '@nestjs/schedule'; | ||
|
||
@Module({ | ||
imports: [ScheduleModule.forRoot()], | ||
controllers: [], | ||
providers: [SaberMonitoringService], | ||
}) | ||
export class AppModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { NestFactory } from '@nestjs/core'; | ||
import { AppModule } from './app.module'; | ||
|
||
async function bootstrap() { | ||
const app = await NestFactory.create(AppModule, { | ||
logger: ['log', 'warn', 'error'], | ||
}); | ||
|
||
await app.listen(process.env.PORT || 8080); | ||
} | ||
|
||
bootstrap(); |
Oops, something went wrong.