Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# backend

## 2.1.11

### Patch Changes

- d9952e7: use merkl api key

## 2.1.10

### Patch Changes
Expand Down
3 changes: 3 additions & 0 deletions apps/api/gql/resolvers/protocol.resolvers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Resolvers } from '../generated-schema';
import { protocolService } from '../../../../modules/protocol/protocol.service';
import { isAdminRoute } from '../../../../modules/auth/auth-context';

const protocolResolvers: Resolvers = {
Query: {
Expand All @@ -12,6 +13,8 @@ const protocolResolvers: Resolvers = {
},
Mutation: {
protocolCacheMetrics: async (parent, { chain }, context): Promise<string> => {
isAdminRoute(context);

await protocolService.cacheProtocolMetrics(chain);
return 'success';
},
Expand Down
2 changes: 2 additions & 0 deletions apps/api/gql/resolvers/user.resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ const resolvers: Resolvers = {
Query: {},
Mutation: {
userSyncChangedWalletBalancesForAllPools: async (parent, { chain }, context) => {
isAdminRoute(context);

await UserBalancesController().syncBalances(chain);

return 'success';
Expand Down
4 changes: 4 additions & 0 deletions apps/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ export const schema = {
type: String,
optional: true,
},
MERKL_API_KEY: {
type: String,
optional: true,
},
};

export const env: Env = load(schema, {
Expand Down
23 changes: 23 additions & 0 deletions config/hyperevm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ export default <NetworkData>{
token: '0x06fd9d03b3d0f18e4919919b72d30c582f0a97e5',
path: '$["0x06Fd9D03b3d0F18E4919919b72D30c582f0a97E5"].supplyAPR',
},
{
type: 'path',
token: '0xb2a2104d9fc202a38d74d8f6c3c45da6eef8f5e0',
path: '$["0xfD739d4e423301CE9385c1fb8850539D657C296D"].supplyAPR',
},
],
},
{
Expand Down Expand Up @@ -145,6 +150,24 @@ export default <NetworkData>{
},
],
},
{
url: 'https://protocol-api.treehouse.finance/protocol_mey',
scale: 100,
convert: async (val: number) => {
const khype = (
(await (await fetch('https://kinetiq.xyz/api/khype')).json()) as { apy_14d: number }
).apy_14d;

return khype + val;
},
extractors: [
{
type: 'path',
token: '0xb83d27f0f4133a7b0377a88089583131a903fdc7',
path: '$[?(@.tasset=="tHYPE")].sma_mey',
},
],
},
{
url: 'https://api.hyperdrive.fi/integrations/hyped/apr',
extractors: [
Expand Down
14 changes: 10 additions & 4 deletions modules/aprs/handlers/merkl-apr/merkl-apr-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ import { $Enums, PrismaPoolAprItem, PrismaPoolAprType } from '@prisma/client';
import { AprHandler, PoolAPRData } from '../../types';
import { chainIdToChain } from '../../../network/chain-id-to-chain';
import { AaveV3Plasma } from '@bgd-labs/aave-address-book';
import { env } from '../../../../apps/env';

const opportunityUrl =
'https://api.merkl.fr/v4/opportunities/?test=false&status=LIVE&campaigns=true&mainProtocolId=balancer&page=0&items=100';
'https://api.merkl.xyz/v4/opportunities/?test=false&status=LIVE&campaigns=true&mainProtocolId=balancer&page=0&items=100';

const tokenOpportunityUrlBase = `https://api.merkl.fr/v4/opportunities/?status=LIVE&explorerAddress=`;
const tokenOpportunityUrlBase = `https://api.merkl.xyz/v4/opportunities/?status=LIVE&explorerAddress=`;

interface MerklOpportunity {
chainId: number;
Expand All @@ -27,7 +28,7 @@ export class MerklAprHandler implements AprHandler {
}

private async fetchMerklOpportunities() {
const response = await fetch(opportunityUrl);
const response = await this.merklFetch(opportunityUrl);
const data = (await response.json()) as MerklOpportunity[];

// remove opportunities with whitelist
Expand Down Expand Up @@ -128,7 +129,7 @@ export class MerklAprHandler implements AprHandler {
// Fetch opportunities for the unique tokens
const tokenOpportunityResponses = await Promise.all(
uniqueTokensWithUnderlying.map((tokenAddress) =>
fetch(`${tokenOpportunityUrlBase}${tokenAddress}`).then(
this.merklFetch(`${tokenOpportunityUrlBase}${tokenAddress}`).then(
(res) => res.json() as unknown as MerklOpportunity[],
),
),
Expand Down Expand Up @@ -259,4 +260,9 @@ export class MerklAprHandler implements AprHandler {
}
return wrapperToATokenMap;
}
private async merklFetch(url: string): Promise<Response> {
const apiKey = env.MERKL_API_KEY;
const headers: Record<string, string> = apiKey ? { 'X-API-Key': apiKey } : {};
return fetch(url, { headers });
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "backend",
"version": "2.1.10",
"version": "2.1.11",
"description": "Backend service for Beethoven X and Balancer",
"repository": "https://github.com/balancer/backend",
"author": "Beethoven X",
Expand Down
Loading