From 83a254f06b9a678ca083500b18213dc884a24946 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Pr=C3=A9vost?= <998369+prevostc@users.noreply.github.com> Date: Wed, 4 Dec 2024 20:53:54 +0100 Subject: [PATCH] add endpoint by strat addy --- README.md | 2 ++ src/routes/v1/partner/camelot.ts | 2 +- src/routes/v1/vault.ts | 59 ++++++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 25db6da..e9b5469 100644 --- a/README.md +++ b/README.md @@ -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 ``` \ No newline at end of file diff --git a/src/routes/v1/partner/camelot.ts b/src/routes/v1/partner/camelot.ts index f8fbe38..dc6a1a0 100644 --- a/src/routes/v1/partner/camelot.ts +++ b/src/routes/v1/partner/camelot.ts @@ -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 => diff --git a/src/routes/v1/vault.ts b/src/routes/v1/vault.ts index cf52e90..fb15456 100644 --- a/src/routes/v1/vault.ts +++ b/src/routes/v1/vault.ts @@ -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; + + 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(); } @@ -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,