Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
franzns committed Dec 20, 2023
2 parents cb8b3e1 + 349f69a commit 6b26333
Show file tree
Hide file tree
Showing 111 changed files with 6,314 additions and 1,669 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ jobs:
- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: '16.x'
node-version: '18.x'
- name: Install deps
run: yarn
run: yarn
- name: Generate Schema
run: yarn generate
- name: Prisma Generate
Expand Down
11 changes: 11 additions & 0 deletions .platform/confighooks/prebuild/env-secret.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/sh
secrets=$(aws secretsmanager get-secret-value --secret-id api-secrets --region $AWS_REGION | jq -r '.SecretString')

IFS=$'\n' read -r -d '' -a keys <<< "$(echo $secrets | jq -r 'keys[]')"

touch .env
chown webapp:webapp .env
for key in "${keys[@]}"; do
value=$(echo $secrets | jq -r ".\"$key\"")
printf "%s=%s\n" "$key" "$value"
done > .env
20 changes: 20 additions & 0 deletions .platform/confighooks/predeploy/env-secret.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/sh
# In case we merge two env secrets into a flattened one in the same region
# secrets=$(aws secretsmanager get-secret-value --secret-id api-secrets --region $AWS_REGION | jq -r '.SecretString')

# IFS=$'\n' read -r -d '' -a key_value_pairs <<< "$(echo $secrets | jq -r --arg prefix "$PREFIX" 'to_entries[] | select((.key | ascii_upcase) | startswith(($prefix+"_") | ascii_upcase)) | ((.key | sub(($prefix+"_"); ""; "i")) + "=" + .value)')"

# for pair in "${key_value_pairs[@]}"; do
# echo "$pair"
# done

secrets=$(aws secretsmanager get-secret-value --secret-id api-secrets --region $AWS_REGION | jq -r '.SecretString')

IFS=$'\n' read -r -d '' -a keys <<< "$(echo $secrets | jq -r 'keys[]')"

touch /var/app/staging/.env
chown webapp:webapp /var/app/staging/.env
for key in "${keys[@]}"; do
value=$(echo $secrets | jq -r ".\"$key\"")
printf "%s=%s\n" "$key" "$value"
done >> /var/app/staging/.env
11 changes: 11 additions & 0 deletions .platform/hooks/prebuild/env-secret.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/sh
secrets=$(aws secretsmanager get-secret-value --secret-id api-secrets --region $AWS_REGION | jq -r '.SecretString')

IFS=$'\n' read -r -d '' -a keys <<< "$(echo $secrets | jq -r 'keys[]')"

touch .env
chown webapp:webapp .env
for key in "${keys[@]}"; do
value=$(echo $secrets | jq -r ".\"$key\"")
printf "%s=%s\n" "$key" "$value"
done > .env
20 changes: 20 additions & 0 deletions .platform/hooks/predeploy/env-secret.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/sh
# In case we merge two env secrets into a flattened one in the same region
# secrets=$(aws secretsmanager get-secret-value --secret-id api-secrets --region $AWS_REGION | jq -r '.SecretString')

# IFS=$'\n' read -r -d '' -a key_value_pairs <<< "$(echo $secrets | jq -r --arg prefix "$PREFIX" 'to_entries[] | select((.key | ascii_upcase) | startswith(($prefix+"_") | ascii_upcase)) | ((.key | sub(($prefix+"_"); ""; "i")) + "=" + .value)')"

# for pair in "${key_value_pairs[@]}"; do
# echo "$pair"
# done

secrets=$(aws secretsmanager get-secret-value --secret-id api-secrets --region $AWS_REGION | jq -r '.SecretString')

IFS=$'\n' read -r -d '' -a keys <<< "$(echo $secrets | jq -r 'keys[]')"

touch /var/app/staging/.env
chown webapp:webapp /var/app/staging/.env
for key in "${keys[@]}"; do
value=$(echo $secrets | jq -r ".\"$key\"")
printf "%s=%s\n" "$key" "$value"
done >> /var/app/staging/.env
30 changes: 14 additions & 16 deletions app.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { loadRestRoutesBeethoven } from './modules/beethoven/loadRestRoutes';
import { loadRestRoutesBalancer } from './modules/balancer/loadRestRoutes';
import { loadRestRoutes } from './modules/common/loadRestRoutes';
import { env } from './app/env';
import createExpressApp from 'express';
import { corsMiddleware } from './app/middleware/corsMiddleware';
Expand All @@ -12,13 +11,12 @@ import {
ApolloServerPluginLandingPageGraphQLPlayground,
ApolloServerPluginUsageReporting,
} from 'apollo-server-core';
import { ApolloServerPlugin } from 'apollo-server-plugin-base';
import { beethovenSchema } from './graphql_schema_generated_beethoven';
import { balancerSchema } from './graphql_schema_generated_balancer';
import { balancerResolvers, beethovenResolvers } from './app/gql/resolvers';
import { schema } from './graphql_schema_generated';
import { resolvers } from './app/gql/resolvers';
import helmet from 'helmet';
import GraphQLJSON from 'graphql-type-json';
import * as Sentry from '@sentry/node';
import { ProfilingIntegration } from '@sentry/profiling-node';
import { sentryPlugin } from './app/gql/sentry-apollo-plugin';
import { startWorker } from './worker/worker';
import { startScheduler } from './worker/scheduler';
Expand All @@ -31,13 +29,17 @@ async function startServer() {
// tracesSampleRate: 0.005,
environment: `multichain-${env.DEPLOYMENT_ENV}`,
enabled: env.NODE_ENV === 'production',
ignoreErrors: [/.*error: Provide.*chain.*param/],
integrations: [
// new Tracing.Integrations.Apollo(),
// new Tracing.Integrations.GraphQL(),
// new Tracing.Integrations.Prisma({ client: prisma }),
// new Tracing.Integrations.Express({ app }),
// new Sentry.Integrations.Http({ tracing: true }),
new Sentry.Integrations.Express({ app }),
new Sentry.Integrations.Http({ tracing: true }),
new ProfilingIntegration(),
],
tracesSampleRate: 0.2,
profilesSampleRate: 0.1,
beforeSend(event, hint) {
const error = hint.originalException as string;
if (error?.toString().includes('Unknown token:')) {
Expand All @@ -57,7 +59,7 @@ async function startServer() {
});

app.use(Sentry.Handlers.requestHandler());
// app.use(Sentry.Handlers.tracingHandler());
app.use(Sentry.Handlers.tracingHandler());
// app.use(Sentry.Handlers.errorHandler());

app.use(helmet.dnsPrefetchControl());
Expand All @@ -76,11 +78,7 @@ async function startServer() {
app.use(contextMiddleware);
app.use(sessionMiddleware);

if (env.PROTOCOL === 'beethoven') {
loadRestRoutesBeethoven(app);
} else if (env.PROTOCOL === 'balancer') {
loadRestRoutesBalancer(app);
}
loadRestRoutes(app);

const httpServer = http.createServer(app);

Expand All @@ -103,9 +101,9 @@ async function startServer() {
const server = new ApolloServer({
resolvers: {
JSON: GraphQLJSON,
...(env.PROTOCOL === 'beethoven' ? beethovenResolvers : balancerResolvers),
...resolvers,
},
typeDefs: env.PROTOCOL === 'beethoven' ? beethovenSchema : balancerSchema,
typeDefs: schema,
introspection: true,
plugins,
context: ({ req }) => req.context,
Expand Down
15 changes: 11 additions & 4 deletions app/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ export const schema = {
SENTRY_DSN: String,
SENTRY_AUTH_TOKEN: String,
AWS_REGION: String,
PROTOCOL: String,
PROTOCOL: {
optional: true,
type: String,
},
INFURA_API_KEY: {
optional: true,
type: String,
Expand All @@ -30,10 +33,14 @@ export const schema = {
optional: true,
type: String,
},
WORKER_QUEUE_URL: String,
WORKER_QUEUE_URL: {
optional: true,
type: String,
},
DATABASE_URL: String,
};

export const env: Env = load(schema, {
path: resolve(__dirname, '../.env'),
overrideProcessEnv: process.env.NODE_ENV !== 'production',
path: resolve(__dirname, `../../.env`),
overrideProcessEnv: true,
});
8 changes: 2 additions & 6 deletions app/gql/resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,5 @@ import { loadFilesSync } from '@graphql-tools/load-files';
import path from 'path';
import { mergeResolvers } from '@graphql-tools/merge';

const balancerResolversArray = loadFilesSync(path.join(__dirname, '../../modules/!(beethoven)/**/*.resolvers.*'));

const beethovenResolversArray = loadFilesSync(path.join(__dirname, '../../modules/!(balancer)/**/*.resolvers.*'));

export const balancerResolvers = mergeResolvers(balancerResolversArray);
export const beethovenResolvers = mergeResolvers(beethovenResolversArray);
const resolversArray = loadFilesSync(path.join(__dirname, '../../modules/**/*.resolvers.*'));
export const resolvers = mergeResolvers(resolversArray);
4 changes: 4 additions & 0 deletions buildspec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ env:
VEBALLOCKS_SUBGRAPH: 'https://api.thegraph.com/subgraphs/name/balancer-labs/balancer-gauges'
phases:
install:
runtime-versions:
nodejs: 18
commands:
- yarn install
build:
Expand All @@ -23,6 +25,8 @@ phases:
- yarn build
post_build:
commands:
- rm -fr node_modules
- yarn install --prod
- echo Build completed on `date`
# - echo Pushing to graph cdn
# - npx graphcdn push
Expand Down
24 changes: 3 additions & 21 deletions codegen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -137,31 +137,13 @@ generates:
schema: ${USER_SNAPSHOT_SUBGRAPH}
plugins:
- schema-ast
graphql_schema_generated_balancer.ts:
schema:
- ./modules/**/*.gql
- '!./modules/beethoven/beets.gql'
- '!./modules/**/*.beets.gql'
plugins:
- add:
content: |
import { gql } from 'apollo-server-express';
export const balancerSchema = gql`
#\n# THIS FILE IS AUTOGENERATED — DO NOT EDIT IT\n#
- schema-ast
- add:
placement: 'append'
content: '`;'
graphql_schema_generated_beethoven.ts:
schema:
- ./modules/**/*.gql
- '!./modules/balancer/balancer.gql'
- '!./modules/**/*.balancer.gql'
graphql_schema_generated.ts:
schema: ./modules/**/*.gql
plugins:
- add:
content: |
import { gql } from 'apollo-server-express';
export const beethovenSchema = gql`
export const schema = gql`
#\n# THIS FILE IS AUTOGENERATED — DO NOT EDIT IT\n#
- schema-ast
- add:
Expand Down
7 changes: 0 additions & 7 deletions modules/balancer/balancer.gql

This file was deleted.

16 changes: 0 additions & 16 deletions modules/balancer/balancer.resolvers.ts

This file was deleted.

5 changes: 0 additions & 5 deletions modules/balancer/loadRestRoutes.ts

This file was deleted.

20 changes: 0 additions & 20 deletions modules/beethoven/balancer-sdk.resolvers.ts

This file was deleted.

2 changes: 1 addition & 1 deletion modules/beethoven/beets.gql
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ extend type Query {

userGetFbeetsBalance: GqlUserFbeetsBalance!

userGetPoolSnapshots(poolId: String!, range: GqlUserSnapshotDataRange!): [GqlUserPoolSnapshot!]!
userGetPoolSnapshots(poolId: String!, chain: GqlChain!, range: GqlUserSnapshotDataRange!): [GqlUserPoolSnapshot!]!
userGetRelicSnapshots(farmId: String!, range: GqlUserSnapshotDataRange!): [GqlUserRelicSnapshot!]!

userGetPortfolioSnapshots(days: Int!): [GqlUserPortfolioSnapshot!]!
Expand Down
3 changes: 2 additions & 1 deletion modules/beethoven/beets.resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,13 @@ const beetsResolvers: Resolvers = {
...balance,
};
},
userGetPoolSnapshots: async (parent, { poolId, range }, context) => {
userGetPoolSnapshots: async (parent, { poolId, chain, range }, context) => {
const accountAddress = getRequiredAccountAddress(context);

return userService.getUserBalanceSnapshotsForPool(
accountAddress.toLowerCase(),
poolId.toLowerCase(),
chain,
range,
);
},
Expand Down
12 changes: 7 additions & 5 deletions modules/coingecko/coingecko.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,10 @@ interface CoinId {
that happen.
*/
const tokensPerInterval = env.COINGECKO_API_KEY ? ((env.DEPLOYMENT_ENV as DeploymentEnv) === 'main' ? 10 : 5) : 3;
const requestRateLimiter = new RateLimiter({ tokensPerInterval, interval: 'minute' });
const tokensPerMinute = env.COINGECKO_API_KEY ? 10 : 3;
const requestRateLimiter = new RateLimiter({ tokensPerInterval: tokensPerMinute, interval: 'minute' });
//max 10 addresses per request because of URI size limit, pro is max 180 because of URI limit
const addressChunkSize = env.COINGECKO_API_KEY ? 180 : 20;

export class CoingeckoService {
private readonly baseUrl: string;
Expand Down Expand Up @@ -104,10 +106,10 @@ export class CoingeckoService {
* Rate limit for the CoinGecko API is 10 calls each second per IP address.
*/
public async getTokenPrices(addresses: string[]): Promise<TokenPrices> {
//max 180 addresses per request because of URI size limit
const addressesPerRequest = 180;
const addressesPerRequest = addressChunkSize;
try {
if (addresses.length / addressesPerRequest > 10) throw new Error('Too many requests for rate limit.');
// if (addresses.length / addressesPerRequest > tokensPerMinute)
// throw new Error('Too many requests for rate limit.');

const tokenDefinitions = await tokenService.getTokenDefinitions([networkContext.chain]);
const mapped = addresses.map((address) => this.getMappedTokenDetails(address, tokenDefinitions));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@ import { Express } from 'express';
import { beetsGetCirculatingSupply } from '../beets/lib/beets';
import { tokenService } from '../token/token.service';

export function loadRestRoutesBeethoven(app: Express) {
export function loadRestRoutes(app: Express) {
app.use('/health', (req, res) => res.sendStatus(200));
app.use('/circulating_supply', (req, res) => {
beetsGetCirculatingSupply().then((result) => {
res.send(result);
});
});

app.use('/late-quartet', async (req, res) => {
const tokenPrices = await tokenService.getTokenPrices();
// app.use('/late-quartet', async (req, res) => {
// const tokenPrices = await tokenService.getTokenPrices();

res.send({
bptPrice: tokenService.getPriceForToken(tokenPrices, '0xf3a602d30dcb723a74a0198313a7551feaca7dac'),
});
});
// res.send({
// bptPrice: tokenService.getPriceForToken(tokenPrices, '0xf3a602d30dcb723a74a0198313a7551feaca7dac'),
// });
// });
}
Loading

0 comments on commit 6b26333

Please sign in to comment.