From 10ff41d0d54e7b83ac9453a2db8c1d3cb6cd0308 Mon Sep 17 00:00:00 2001 From: Philippe Date: Wed, 14 Jun 2023 16:45:08 +0200 Subject: [PATCH] Add getPools/all endpoint --- endpoints.md | 3 +++ pages/api/getPools/all.js | 13 +++++++++++++ pages/api/getPools/index.js | 2 +- 3 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 pages/api/getPools/all.js diff --git a/endpoints.md b/endpoints.md index 861839f2..44ee6712 100644 --- a/endpoints.md +++ b/endpoints.md @@ -59,6 +59,9 @@ GET /api/getPools// - https://api.curve.fi/api/getPools/xdai/crypto - https://api.curve.fi/api/getPools/xdai/factory +This endpoint returns *all* pools from all these registries, in exactly the same shape, except for the fact that each pool object will also contain a `blockchainId` prop. +For each pool object in the endpoints above, the `id` prop is unique. For each pool object in this single "all pools" endpoint, the combination of props `blockchainId` and `id` is unique. + ### getETHprice ``` GET /api/getETHprice diff --git a/pages/api/getPools/all.js b/pages/api/getPools/all.js new file mode 100644 index 00000000..2d6e6fd5 --- /dev/null +++ b/pages/api/getPools/all.js @@ -0,0 +1,13 @@ +import configs from 'constants/configs'; +import getAllCurvePoolsData from 'utils/data/curve-pools-data'; +import { fn } from 'utils/api'; + +const allBlockchainIds = Array.from(Object.keys(configs)); +console.log({ allBlockchainIds }) + +export default fn(async () => ( + getAllCurvePoolsData(allBlockchainIds) +), { + maxAge: 5 * 60, + name: 'getAllPools', +}); diff --git a/pages/api/getPools/index.js b/pages/api/getPools/index.js index 71c39c2b..ae6f620d 100644 --- a/pages/api/getPools/index.js +++ b/pages/api/getPools/index.js @@ -255,7 +255,7 @@ const getPools = async ({ blockchainId, registryId, preventQueryingFactoData }) registryId === 'factory-eywa' ? await getFactoryEywaRegistryAddress() : undefined ); - if (registryAddress === ZERO_ADDRESS) return { poolData: [], tvlAll: 0 }; + if (registryAddress === ZERO_ADDRESS || !registryAddress) return { poolData: [], tvlAll: 0 }; const getIdForPool = (id) => ( registryId === 'factory' ? `factory-v2-${id}` :