Skip to content

Commit

Permalink
Add bundles config url
Browse files Browse the repository at this point in the history
  • Loading branch information
prevostc committed Dec 2, 2024
1 parent cee24ab commit e2ef44c
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ https://balance-api.beefy.finance/api/v1/config/arbitrum/vaults?include_eol=true
http://localhost:4000/api/v1/config/arbitrum/vaults?include_eol=true
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/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
60 changes: 60 additions & 0 deletions src/routes/v1/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,65 @@ export default async function (
);
}

// 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: ['vault'],
params: urlParamsSchema,
querystring: queryParamsSchema,
response: {
200: responseSchema,
},
};

instance.get<{ Params: UrlParams; Querystring: QueryParams }>(
'/: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'
);

// 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();
}

0 comments on commit e2ef44c

Please sign in to comment.