Skip to content

Commit

Permalink
Merge pull request #258 from dappradar/add-redis-instance
Browse files Browse the repository at this point in the history
Add redis instance
  • Loading branch information
ebusho authored Feb 22, 2024
2 parents 2c0b415 + ef5af53 commit 982d940
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 16 deletions.
6 changes: 5 additions & 1 deletion .env.dev
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,8 @@ LOGSTASH_INDEX=
#=================== SLACK WEB HOOK ===================
SLACK_WEBHOOK_URL=
SLACK_LOGGING=false
REDIS_URL=

REDIS_HOST=
REDIS_PORT=6379
REDIS_USERNAME=
REDIS_PASSWORD=
2 changes: 1 addition & 1 deletion kubernetes/base/kustomization.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ resources:
- service.yml
- ingress.yml
- secrets.yml
# - redis.yml
- redis.yml
37 changes: 29 additions & 8 deletions kubernetes/base/redis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: defi-providers-redis-pvc
spec:
accessModes:
- ReadWriteOnce
storageClassName: gp3
resources:
requests:
storage: 1G
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: defi-providers-redis
spec:
replicas: 0
replicas: 1
selector:
matchLabels:
component: defi-providers-redis
Expand All @@ -14,27 +26,36 @@ spec:
spec:
containers:
- name: defi-providers-redis
image: redis:7.0.11
image: redis:7
imagePullPolicy: Always
args: ["--requirepass", "$(REDIS_PASS)"]
args: ["--requirepass", "$(REDIS_PASSWORD)"]
resources:
requests:
cpu: 250m
memory: 512Mi
cpu: 100m
memory: 512M
limits:
cpu: 1000m
memory: 1Gi
memory: 1G
ports:
- name: redis-port
containerPort: 6379
env:
- name: MASTER
value: "true"
- name: REDIS_PASS
- name: REDIS_PASSWORD
valueFrom:
secretKeyRef:
name: defi-providers-secrets
key: REDIS_PASS
key: REDIS_PASSWORD
volumeMounts:
- name: redis-data
mountPath: /data
volumes:
- name: redis-data
persistentVolumeClaim:
claimName: defi-providers-redis-pvc
strategy: # temporary hack around "ReadWriteOnce" access mode issue (https://stackoverflow.com/a/62230273/4725013)
type: Recreate
---
apiVersion: v1
kind: Service
Expand Down
11 changes: 8 additions & 3 deletions src/app.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { resolve } from 'path';
import * as dotenv from 'dotenv';
dotenv.config();
dotenv.config({ path: `.env.${process.env.APP_ENV || 'dev'}` });
Expand All @@ -14,7 +13,10 @@ const {
LOGSTASH_HOST,
LOGSTASH_INDEX,
BASE_URL = './blockchainCache/',
REDIS_URL,
REDIS_HOST,
REDIS_PORT,
REDIS_USERNAME,
REDIS_PASSWORD,
} = process.env;

const config = {
Expand All @@ -28,7 +30,10 @@ const config = {
SLACK_WEBHOOK_URL,
SLACK_LOGGING,
BASE_URL,
REDIS_URL,
REDIS_HOST,
REDIS_PORT,
REDIS_USERNAME,
REDIS_PASSWORD,
};

const nodeUrls: { [key: string]: string } = {};
Expand Down
57 changes: 57 additions & 0 deletions src/factory/providers/ethereum/eigenlayer/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import BigNumber from 'bignumber.js';
import { ITvlParams, ITvlReturn } from '../../../../interfaces/ITvl';
import { request, gql } from 'graphql-request';
import formatter from '../../../../util/formatter';

const START_BLOCK = 17445564;
const SWETH = '0xf951e335afb289353dc249e82926178eac7ded78';

const SUBGRAPH_ENDPOINT =
'https://api.thegraph.com/subgraphs/name/messari/eigenlayer-ethereum';
const STRATEGY_POOLS = gql`
query getPools($block: Int!) {
protocols(block: { number: $block }) {
totalEigenPodCount
}
pools(block: { number: $block }, where: { type: STRATEGY }) {
inputTokens {
id
}
inputTokenBalances
}
}
`;

async function tvl(params: ITvlParams): Promise<Partial<ITvlReturn>> {
const { block, chain, provider, web3 } = params;

if (block < START_BLOCK) {
return {};
}
const balances = {};

const requestResult = await request(SUBGRAPH_ENDPOINT, STRATEGY_POOLS, {
block: block,
});

balances['eth'] = BigNumber(
requestResult.protocols[0].totalEigenPodCount * 38,
).shiftedBy(18);

for (const pool of requestResult.pools) {
for (let i = 0; i < pool.inputTokens.length; i++) {
balances[pool.inputTokens[i].id.toLowerCase()] = BigNumber(
balances[pool.inputTokens[i].id.toLowerCase()] || 0,
).plus(BigNumber(pool.inputTokenBalances[i]));
}
}
if (balances[SWETH]) {
balances['eth'] = BigNumber(balances['eth']).plus(balances[SWETH]);
delete balances[SWETH];
}

formatter.convertBalancesToFixed(balances);
return { balances };
}

export { tvl };
6 changes: 3 additions & 3 deletions src/util/redis.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { createClient } from 'redis';
import { log } from './logger/logger';
import { config } from '../app.config';
const { REDIS_URL } = config;
const { REDIS_HOST, REDIS_PORT, REDIS_USERNAME, REDIS_PASSWORD } = config;
let client;

function Redis() {
if (!client && REDIS_URL) {
if (!client && REDIS_HOST) {
client = createClient({
url: REDIS_URL,
url: `redis://${REDIS_USERNAME}:${REDIS_PASSWORD}@${REDIS_HOST}:${REDIS_PORT}`,
});
client.connect();
}
Expand Down

0 comments on commit 982d940

Please sign in to comment.