Skip to content

Commit

Permalink
Add camelot config url
Browse files Browse the repository at this point in the history
  • Loading branch information
prevostc committed Dec 4, 2024
1 parent e2ef44c commit 48a8dfb
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ https://balance-api.beefy.finance/api/v1/config/arbitrum/bundles
http://localhost:4000/api/v1/config/arbitrum/bundles
https://balance-api.beefy.finance/api/v1/partner/camelot/config/arbitrum/bundles
http://localhost:4000/api/v1/partner/camelot/config/arbitrum/bundles
https://balance-api.beefy.finance/api/v1/vault/base/baseswap-cow-weth-cbbtc/20449610/bundle-holder-share
http://localhost:4000/api/v1/vault/base/baseswap-cow-weth-cbbtc/20449610/bundle-holder-share
https://balance-api.beefy.finance/api/v1/vault/arbitrum/camelot-order-weth/279181618/bundle-holder-share
Expand Down
2 changes: 2 additions & 0 deletions src/routes/v1/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { FastifyInstance, FastifyPluginOptions } from 'fastify';
import config from './config';
import contract from './contract';
import holders from './holders';
import partner from './partner';
import status from './status';
import vault from './vault';

Expand All @@ -15,5 +16,6 @@ export default async function (
instance.register(vault, { prefix: '/vault' });
instance.register(config, { prefix: '/config' });
instance.register(contract, { prefix: '/contract' });
instance.register(partner, { prefix: '/partner' });
done();
}
78 changes: 78 additions & 0 deletions src/routes/v1/partner/camelot.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import { type Static, Type } from '@sinclair/typebox';
import type { FastifyInstance, FastifyPluginOptions, FastifySchema } from 'fastify';
import { chainIdSchema } from '../../../config/chains';
import { getAsyncCache } from '../../../utils/async-lock';
import { getBeefyVaultConfig } from '../../../vault-breakdown/vault/getBeefyVaultConfig';

export default async function (
instance: FastifyInstance,
_opts: FastifyPluginOptions,
done: (err?: Error) => void
) {
const asyncCache = getAsyncCache();

// all configs with point structure id of some chain
{
const urlParamsSchema = Type.Object({
chain: chainIdSchema,
});
type UrlParams = Static<typeof urlParamsSchema>;
const responseSchema = Type.Object({
vaults: Type.Array(Type.Any()),
});

const queryParamsSchema = Type.Object({
include_eol: Type.Optional(Type.Boolean({ default: false })),
});
type QueryParams = Static<typeof queryParamsSchema>;

const schema: FastifySchema = {
tags: ['camelot'],
params: urlParamsSchema,
querystring: queryParamsSchema,
response: {
200: responseSchema,
},
};

instance.get<{ Params: UrlParams; Querystring: QueryParams }>(
'/config/:chain/bundles',
{ schema },
async (request, reply) => {
const { chain } = request.params;
const { include_eol } = request.query;

const result = await asyncCache.wrap(`config:${chain}`, 5 * 60 * 1000, async () => {
const configs = await getBeefyVaultConfig(
chain,
vault =>
(include_eol ? true : vault.status === 'active') &&
vault.underlyingPlatform === 'camelot'
);

// remove clm vault from top levels if a vault exists on top
const clmVaultAddresses = new Set(
configs
.map(vault =>
vault.protocol_type === 'beefy_clm_vault'
? vault.beefy_clm_manager.vault_address
: null
)
.map(address => address?.toLowerCase())
.filter(Boolean)
);

console.log(clmVaultAddresses);

const filteredConfigs = configs.filter(
vault => !clmVaultAddresses.has(vault.vault_address.toLowerCase())
);
return filteredConfigs;
});
reply.send(result);
}
);
}

done();
}
10 changes: 10 additions & 0 deletions src/routes/v1/partner/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import type { FastifyInstance, FastifyPluginOptions } from 'fastify';
import camelot from './camelot';
export default async function (
instance: FastifyInstance,
_opts: FastifyPluginOptions,
done: (err?: Error) => void
) {
instance.register(camelot, { prefix: '/camelot' });
done();
}
8 changes: 8 additions & 0 deletions src/vault-breakdown/vault/getBeefyVaultConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export type BeefyVault = {
pointStructureIds: string[];
platformId: ApiPlatformId;
status: 'active' | 'eol';
underlyingPlatform: string | null;
} & (
| {
protocol_type: 'beefy_clm_vault';
Expand Down Expand Up @@ -109,6 +110,7 @@ export type ApiClmManager = {
earnContractAddress: string; // reward pool address
earnedTokenAddress: string; // clm manager address
pointStructureIds?: string[];
tokenProviderId?: string;
};

export type ApiClmRewardPool = {
Expand Down Expand Up @@ -246,6 +248,7 @@ const getAllConfigs = async (chain: ChainId): Promise<BeefyVault[]> => {
const reward_pools = clmRewardPoolDataPerClmAddress[vault_address] ?? [];

const boosts = boostPerUnderlyingAddress[vault_address] ?? [];
const underlyingPlatform = vault.tokenProviderId ?? null;

return {
id: vault.id,
Expand All @@ -257,6 +260,7 @@ const getAllConfigs = async (chain: ChainId): Promise<BeefyVault[]> => {
status: vault.status,
strategy_address: vault.strategy.toLocaleLowerCase() as Hex,
undelying_lp_address,
underlyingPlatform,
reward_pools: reward_pools.map(pool => ({
id: pool.id,
clm_address: pool.tokenAddress.toLocaleLowerCase() as Hex,
Expand Down Expand Up @@ -305,12 +309,16 @@ const getAllConfigs = async (chain: ChainId): Promise<BeefyVault[]> => {
: { protocol_type, platformId: vault.platformId };
const reward_pools = vaultRewardPoolDataPerVaultAddress[vault_address] ?? [];
const boosts = boostPerUnderlyingAddress[vault_address] ?? [];

const underlyingPlatform = vault.platformId ?? null;

return {
id: vault.id,
vault_address,
chain: vault.chain,
vault_token_symbol: vault.earnedToken,
...additionalConfig,
underlyingPlatform,
strategy_address: vault.strategy.toLocaleLowerCase() as Hex,
undelying_lp_address: underlying_lp_address,
status: vault.status,
Expand Down

0 comments on commit 48a8dfb

Please sign in to comment.