diff --git a/scripts/build-products.js b/scripts/build-products.js index f220291e..b48454e9 100644 --- a/scripts/build-products.js +++ b/scripts/build-products.js @@ -6,7 +6,7 @@ const { CoverProducts, Cover, addresses } = require('@nexusmutual/deployments'); const ethers = require('ethers'); const fetch = require('node-fetch'); -const { parseProductCoverAssets, parseFilePath, getCoverAssetsSymbols } = require('./utils'); +const { parseProductCoverAssets, parseFilePath, getCoverAssetsSymbols, fetchEventsInBatches } = require('./utils'); const { allPrivateProductsIds } = require(path.join(__dirname, '../src/constants/privateProducts.js')); const productMetadata = require('../data/legacy-product-metadata.json'); @@ -60,9 +60,12 @@ const createLogoDict = async logosDir => { return map; }; +const EVENTS_START_BLOCK = 7700000; + const fetchProducts = async (coverContract, coverProducts, provider) => { const eventFilter = coverProducts.filters.ProductSet(); - const events = await coverProducts.queryFilter(eventFilter); + + const events = await fetchEventsInBatches(coverProducts, eventFilter, EVENTS_START_BLOCK, provider); const logos = await createLogoDict(path.join(__dirname, '../src/logos')); diff --git a/scripts/utils.js b/scripts/utils.js index baee37f1..e688414f 100644 --- a/scripts/utils.js +++ b/scripts/utils.js @@ -79,9 +79,39 @@ const parseFilePath = filePath => { return { id, filename, extension }; }; +/** + * Fetches events in batches to avoid RPC limitations. + * All batches are fetched in parallel for better performance. + * + * @param {ethers.Contract} contract - The contract to query events from. + * @param {ethers.EventFilter} eventFilter - The event filter to apply. + * @param {number} startBlock - The starting block number. + * @param {ethers.providers.Provider} provider - The Ethereum provider to interact with the blockchain. + * @param {number} [batchSize=10000] - The number of blocks to query per batch. + * @returns {Promise} A promise that resolves to an array of events. + */ +const fetchEventsInBatches = async (contract, eventFilter, startBlock, provider, batchSize = 10_000) => { + const endBlock = await provider.getBlockNumber(); + const batches = []; + + for (let fromBlock = startBlock; fromBlock <= endBlock; fromBlock += batchSize) { + const toBlock = Math.min(fromBlock + batchSize - 1, endBlock); + batches.push({ fromBlock, toBlock }); + } + + const batchResults = await Promise.all( + batches.map(({ fromBlock, toBlock }) => { + return contract.queryFilter(eventFilter, fromBlock, toBlock); + }), + ); + + return batchResults.flat(); +}; + module.exports = { parseProductCoverAssets, parseCoverAssetToProductAsset, parseFilePath, getCoverAssetsSymbols, + fetchEventsInBatches, }; diff --git a/src/constants/privateProducts.js b/src/constants/privateProducts.js index dc5bb42c..cb265cda 100644 --- a/src/constants/privateProducts.js +++ b/src/constants/privateProducts.js @@ -94,6 +94,8 @@ const allPrivateProductsIds = [ 400, // OpenCover Steakhouse H Yield I USDC 401, // PT-stcUSD-23JUL2026 (Morpho) 402, // PT-cUSD-23JUL2026 (Morpho) + 403, // TermMax + 405, // OpenCover YoUSD ]; module.exports = { diff --git a/src/constants/products.ts b/src/constants/products.ts index 7c7aff51..5d50c962 100644 --- a/src/constants/products.ts +++ b/src/constants/products.ts @@ -396,4 +396,5 @@ export const productCategoryMap: { [productId: number]: ProductCategoryEnum } = 387: ProductCategoryEnum.Depeg, // Neutrl USD Depeg 388: ProductCategoryEnum.Dex, // Hybra Finance 391: ProductCategoryEnum.YieldOptimizer, // IPOR + 404: ProductCategoryEnum.Custody, // BingX Custody }; diff --git a/src/logos/403-termmax.svg b/src/logos/403-termmax.svg new file mode 100644 index 00000000..8f2a253a --- /dev/null +++ b/src/logos/403-termmax.svg @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/logos/404-bingx.svg b/src/logos/404-bingx.svg new file mode 100644 index 00000000..9bcb83f4 --- /dev/null +++ b/src/logos/404-bingx.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/logos/405-open-cover.svg b/src/logos/405-open-cover.svg new file mode 100644 index 00000000..30eba5c9 --- /dev/null +++ b/src/logos/405-open-cover.svg @@ -0,0 +1,52 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file