Skip to content

Commit

Permalink
add endpoint by strat addy
Browse files Browse the repository at this point in the history
  • Loading branch information
prevostc committed Dec 4, 2024
1 parent 48a8dfb commit 83a254f
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ https://balance-api.beefy.finance/api/v1/vault/arbitrum/0x42cf53622b413b40cb24f7
http://localhost:4000/api/v1/vault/arbitrum/0x42cf53622b413b40cb24f78a79e0e76e587b7f33/279181618/bundle-holder-share-by-vault-address
https://balance-api.beefy.finance/api/v1/vault/arbitrum/0xf4ea976b260a498f26417b89f6dbdd555104a734/279181618/bundle-holder-share-by-vault-address
http://localhost:4000/api/v1/vault/arbitrum/0xf4ea976b260a498f26417b89f6dbdd555104a734/279181618/bundle-holder-share-by-vault-address
https://balance-api.beefy.finance/api/v1/vault/arbitrum/0xf4ea976b260a498f26417b89f6dbdd555104a734/279181618/bundle-holder-share-by-strategy-address
http://localhost:4000/api/v1/vault/arbitrum/0xf4ea976b260a498f26417b89f6dbdd555104a734/279181618/bundle-holder-share-by-strategy-address
```
2 changes: 1 addition & 1 deletion src/routes/v1/partner/camelot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export default async function (
const { chain } = request.params;
const { include_eol } = request.query;

const result = await asyncCache.wrap(`config:${chain}`, 5 * 60 * 1000, async () => {
const result = await asyncCache.wrap(`camelot:config:${chain}`, 5 * 60 * 1000, async () => {
const configs = await getBeefyVaultConfig(
chain,
vault =>
Expand Down
59 changes: 59 additions & 0 deletions src/routes/v1/vault.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,45 @@ export default async function (
);
}

// all holder count list for all chains
{
const urlParamsSchema = Type.Object({
chain: chainIdSchema,
strategy_address: addressSchema,
block_number: bigintSchema,
});
type UrlParams = Static<typeof urlParamsSchema>;

const schema: FastifySchema = {
tags: ['vault'],
params: urlParamsSchema,
response: {
200: vaultHoldersSchema,
},
};

instance.get<{ Params: UrlParams }>(
'/:chain/:strategy_address/:block_number/bundle-holder-share-by-strategy-address',
{ schema },
async (request, reply) => {
const { chain, strategy_address, block_number } = request.params;

const result = await asyncCache.wrap(
`vault:${chain}:${strategy_address}:${block_number}:holders`,
5 * 60 * 1000,
async () =>
getVaultHoldersAsBaseVaultEquivalentForStrategyAddress(
chain,
strategy_address as Hex,
BigInt(block_number)
)
);

reply.send(result);
}
);
}

done();
}

Expand Down Expand Up @@ -275,6 +314,26 @@ const getVaultHoldersAsBaseVaultEquivalentForVaultAddress = async (
return _getVaultHoldersAsBaseVaultEquivalent(chainId, configs[0], block);
};

const getVaultHoldersAsBaseVaultEquivalentForStrategyAddress = async (
chainId: ChainId,
strategy_address: Hex,
block: bigint
) => {
// first get the addresses linked to that vault id
const configs = await getBeefyBreakdownableVaultConfig(
chainId,
vault => vault.strategy_address === strategy_address
);
if (!configs.length) {
throw new Error(`Vault with "strategy_address" ${strategy_address} not found`);
}
if (configs.length > 1) {
throw new Error(`Vault with "strategy_address" ${strategy_address} is not unique`);
}

return _getVaultHoldersAsBaseVaultEquivalent(chainId, configs[0], block);
};

const getVaultHoldersAsBaseVaultEquivalentForVaultId = async (
chainId: ChainId,
vault_id: string,
Expand Down

0 comments on commit 83a254f

Please sign in to comment.