Skip to content

Commit

Permalink
feature: enable protocol health api
Browse files Browse the repository at this point in the history
  • Loading branch information
benefacto authored and okjintao committed Jul 6, 2021
1 parent 5297ebb commit 520dedb
Show file tree
Hide file tree
Showing 83 changed files with 19,943 additions and 795 deletions.
8 changes: 8 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ module.exports = {
'plugin:prettier/recommended',
'prettier',
],
overrides: [
{
files: ['*.ts', '*.tsx'], // Your TypeScript files extension
parserOptions: {
project: ['./tsconfig.json'], // Specify it only for TypeScript files
},
}
],
rules: {
'@typescript-eslint/await-thenable': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
Expand Down
96 changes: 96 additions & 0 deletions docs/health.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# Maintaining Health Endpoints
In the [health controller](../src/health/health.controller.ts), a number of health monitoring endpoints are defined that return basic health information on certain sources: APIs, smart contracts, subgraphs, and web3 providers. As sources are added, changed, or removed, the configuration for these endpoints will need to be updated.

## APIs

APIs can be added or removed by modifying the `apis` variable in the [health.config.ts](../src/health/health.config.ts) file:
```ts
export const apis: Endpoint[] = [
{ name: 'Some API', url: new URL('https://some.endpoint.com') },
{ name: 'Some Other API', url: new URL(SOME_ENV_VARIABLE) },
];
```
Valid return status codes are defined in `ApisHealthService` in [health.service.ts](../src/health/health.service.ts).

## Smart Contracts

Smart contracts' ABIs should be exported from the [abi folder](../src/config/abi/) depending on their chain.
For example Ethereum ABIs are exported from [health-eth-abis.ts](../src/config/abi/health-eth-abis.ts) whereas Binance Smart Chain ABIs are exported from [health-bsc-abis.ts](../src/config/abi/health-bsc-abis.ts).
ABIs should be defined in their own file similar to the following format:
```ts
export const contract = 'contractAddress';
export const abi = [
{
anonymous: false,
inputs: [
//...
],
name: 'SomeEvent',
type: 'event',
},
{
anonymous: false,
inputs: [
//...
],
outputs: [
//...
],
name: 'SomeFunction',
type: 'function',
},
//...
];
```

Addition or removal of chains requires code change to the `ContractsHealthService` defined in [health.service.ts](../src/health/health.service.ts).

## Subgraphs

Subgraphs (and their queries) can be added or removed by modifying the `subgraphs` variable in the [health.config.ts](../src/health/health.config.ts) file:
```ts
export const subgraphs: Subgraph[] = [
{
name: 'SOME SUBGRAPH',
url: new URL(SOME_ENV_VARIABLE),
query: gql`
{
someObject(first: 5) {
id
someProperty
}
someOtherObject(first: 5) {
id
someProperty
}
}
`,
},
{
name: 'SOME OTHER SUBGRAPH',
url: new URL(SOME_OTHER_ENV_VARIABLE),
query: gql`
{
someObject(first: 5) {
id
someProperty
}
someOtherObject(first: 5) {
id
someProperty
}
}
`,
},
];
```

## Web3 Providers

Web3 providers can be added or removed by modifying the `providers` variable in the [health.config.ts](../src/health/health.config.ts) file:
```ts
export const providers: Endpoint[] = [
{ name: 'ThisOne', url: new URL(Provider.ThisOne) },
{ name: 'ThatOne', url: new URL(Provider.ThatOne) },
];
```
54 changes: 27 additions & 27 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,61 +30,61 @@
"@tsed/schema": "6.53.0",
"@tsed/swagger": "6.53.0",
"@types/cors": "^2.8.10",
"aws-sdk": "^2.834.0",
"aws-sdk": "^2.913.0",
"body-parser": "^1.19.0",
"class-transformer": "0.4.0",
"class-validator": "0.13.1",
"cookie-parser": "^1.4.5",
"cors": "^2.8.5",
"ethers": "^5.0.26",
"globby": "^11.0.2",
"ethers": "^5.2.0",
"globby": "^11.0.3",
"graphql": "^15.5.0",
"graphql-request": "^3.4.0",
"graphql-tag": "^2.11.0",
"graphql-tag": "^2.12.4",
"method-override": "^3.0.0",
"node-cache": "^5.1.2",
"node-fetch": "^2.6.1",
"serverless-dynamodb-client": "^0.0.2",
"tslib": "^2.1.0"
"tslib": "^2.2.0"
},
"devDependencies": {
"@graphql-codegen/cli": "1.21.1",
"@graphql-codegen/typescript": "1.21.0",
"@graphql-codegen/typescript-graphql-request": "3.0.2",
"@graphql-codegen/typescript-operations": "1.17.14",
"@graphql-codegen/cli": "1.21.4",
"@graphql-codegen/typescript": "1.22.0",
"@graphql-codegen/typescript-graphql-request": "3.2.0",
"@graphql-codegen/typescript-operations": "1.17.16",
"@types/cookie-parser": "^1.4.2",
"@types/express": "^4.17.11",
"@types/jest": "^26.0.20",
"@types/jest": "^26.0.23",
"@types/jsonfile": "^6.0.0",
"@types/method-override": "^0.0.31",
"@types/multer": "^1.4.5",
"@types/node": "^14.14.24",
"@types/node-fetch": "^2.5.8",
"@types/supertest": "2.0.10",
"@types/node": "^15.6.1",
"@types/node-fetch": "^2.5.10",
"@types/supertest": "2.0.11",
"@types/web3": "^1.2.2",
"@typescript-eslint/eslint-plugin": "^4.14.1",
"@typescript-eslint/parser": "^4.14.1",
"dotenv": "8.2.0",
"eslint": "^7.18.0",
"eslint-config-prettier": "^7.2.0",
"eslint-plugin-import": "2.22.1",
"eslint-plugin-jest": "24.1.5",
"eslint-plugin-prettier": "^3.3.1",
"@typescript-eslint/eslint-plugin": "^4.25.0",
"@typescript-eslint/parser": "^4.25.0",
"dotenv": "10.0.0",
"eslint": "^7.27.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-import": "2.23.3",
"eslint-plugin-jest": "24.3.6",
"eslint-plugin-prettier": "^3.4.0",
"eslint-plugin-simple-import-sort": "7.0.0",
"ethers-typescript-typings": "^0.0.4",
"express": "4",
"jest": "^26.6.3",
"jest-create-mock-instance": "1.1.0",
"jest-fetch-mock": "^3.0.3",
"jsonfile": "^6.1.0",
"prettier": "^2.2.1",
"serverless": "^2.23.0",
"prettier": "^2.3.0",
"serverless": "^2.43.0",
"serverless-dynamodb-local": "^0.2.39",
"serverless-offline": "^6.8.0",
"serverless-offline": "^7.0.0",
"serverless-plugin-typescript": "^1.1.9",
"supertest": "6.1.3",
"ts-jest": "^26.5.0",
"ts-node": "^9.1.1",
"typescript": "^4.1.3"
"ts-jest": "^26.5.6",
"ts-node": "^10.0.0",
"typescript": "^4.2.4"
}
}
33 changes: 32 additions & 1 deletion serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ functions:
- schedule:
name: ${self:service}-${self:custom.stage}-index-setts
description: "index historical data for all setts"
rate: rate(10 minutes)
rate: rate(15 minutes)

index-apy-snapshots:
handler: src/indexer/apy-snapshots-indexer.refreshApySnapshots
Expand Down Expand Up @@ -277,11 +277,16 @@ functions:
index-leaderboard:
handler: src/indexer/boost-indexer.indexBoostLeaderBoard
timeout: 60
<<<<<<< HEAD
<<<<<<< HEAD
=======
>>>>>>> feat(health): uncomment scheduled serverless functions
events:
- schedule:
name: ${self:service}-${self:custom.stage}-index-leaderboard
description: "index leaderboard data from latest badger boosts"
rate: rate(1 hour)
<<<<<<< HEAD

index-token-balances:
handler: src/indexer/token-balances-indexer.refreshTokenBalances
Expand All @@ -300,3 +305,29 @@ functions:
name: ${self:service}-${self:custom.stage}-index-accounts
description: "index accounts information from the graph"
rate: rate(1 hour)
=======
# events:
# - schedule:
# name: ${self:service}-${self:custom.stage}-index-leaderboard
# description: "index leaderboard data from latest badger boosts"
# rate: rate(1 minute)
=======
>>>>>>> feat(health): uncomment scheduled serverless functions

index-token-balances:
handler: src/indexer/token-balances-indexer.refreshTokenBalances
timeout: 60
<<<<<<< HEAD
# events:
# - schedule:
# name: ${self:service}-${self:custom.stage}-index-token-balances
# description: "index token balances from the graph"
# rate: rate(1 minute)
>>>>>>> feat(health): rework subgraph configuration, refactor
=======
events:
- schedule:
name: ${self:service}-${self:custom.stage}-index-token-balances
description: "index token balances from the graph"
rate: rate(1 minute)
>>>>>>> feat(health): uncomment scheduled serverless functions
2 changes: 2 additions & 0 deletions src/ControllerRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { ChartsController } from './charts/charts.controller';
import { ClawController } from './claw/claw.controller';
import { HarvestsController } from './harvests/harvests.controller';
import { LeaderBoardsController } from './leaderboards/leaderboards.controller';
import { HealthController } from './health/health.controller';
import { PriceController } from './prices/prices.controller';
import { ProtocolController } from './protocols/protocols.controller';
import { RewardController } from './rewards/rewards.controller';
Expand All @@ -26,4 +27,5 @@ export const controllers = [
AccountsController,
LeaderBoardsController,
TokensController,
HealthController,
];
1 change: 1 addition & 0 deletions src/chains/config/bsc.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export class BinanceSmartChain extends Chain {
bscTokensConfig,
bscSetts,
new ethers.providers.JsonRpcProvider(Provider.Binance),
new ethers.providers.JsonRpcBatchProvider(Provider.Binance),
new BscStrategy(),
BADGER_BSC_URL,
10512000,
Expand Down
3 changes: 3 additions & 0 deletions src/chains/config/chain.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export abstract class Chain {
readonly tokens: TokenConfig;
readonly setts: SettDefinition[];
readonly provider: ethers.providers.JsonRpcProvider;
readonly batchProvider: ethers.providers.JsonRpcBatchProvider;
readonly strategy: ChainStrategy;
readonly graphUrl: string;
readonly blocksPerYear: number;
Expand All @@ -29,6 +30,7 @@ export abstract class Chain {
tokens: TokenConfig,
setts: SettDefinition[],
provider: ethers.providers.JsonRpcProvider,
batchProvider: ethers.providers.JsonRpcBatchProvider,
strategy: ChainStrategy,
graphUrl: string,
blocksPerYear: number,
Expand All @@ -40,6 +42,7 @@ export abstract class Chain {
this.tokens = tokens;
this.setts = setts.filter((sett) => !sett.stage || sett.stage === STAGE);
this.provider = provider;
this.batchProvider = batchProvider;
this.strategy = strategy;
this.graphUrl = graphUrl;
this.blocksPerYear = blocksPerYear;
Expand Down
1 change: 1 addition & 0 deletions src/chains/config/eth.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export class Ethereum extends Chain {
ethTokensConfig,
ethSetts,
new ethers.providers.JsonRpcProvider(Provider.Alchemy),
new ethers.providers.JsonRpcBatchProvider(Provider.Alchemy),
new EthStrategy(),
BADGER_URL,
2425847,
Expand Down
Loading

0 comments on commit 520dedb

Please sign in to comment.