@merkl/api 0.10.129 → 0.10.130
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/database/api/.generated/default.js +1 -0
- package/dist/database/api/.generated/edge.js +609 -0
- package/dist/database/api/.generated/index-browser.js +586 -0
- package/dist/database/api/.generated/index.js +638 -0
- package/dist/database/api/.generated/runtime/edge-esm.js +31 -0
- package/dist/database/api/.generated/runtime/edge.js +31 -0
- package/dist/database/api/.generated/runtime/index-browser.js +13 -0
- package/dist/database/api/.generated/runtime/library.js +143 -0
- package/dist/database/api/.generated/runtime/react-native.js +80 -0
- package/dist/database/api/.generated/runtime/wasm.js +32 -0
- package/dist/database/api/.generated/wasm.js +586 -0
- package/dist/database/api/seeder/resources/protocol.js +341 -0
- package/dist/database/engine/.generated/default.js +1 -0
- package/dist/database/engine/.generated/edge.js +438 -0
- package/dist/database/engine/.generated/index-browser.js +415 -0
- package/dist/database/engine/.generated/index.js +467 -0
- package/dist/database/engine/.generated/runtime/edge-esm.js +31 -0
- package/dist/database/engine/.generated/runtime/edge.js +31 -0
- package/dist/database/engine/.generated/runtime/index-browser.js +13 -0
- package/dist/database/engine/.generated/runtime/library.js +143 -0
- package/dist/database/engine/.generated/runtime/react-native.js +80 -0
- package/dist/database/engine/.generated/runtime/wasm.js +32 -0
- package/dist/database/engine/.generated/wasm.js +415 -0
- package/dist/node_modules/@elysiajs/eden/eden/LICENSE +7 -0
- package/dist/node_modules/@elysiajs/eden/eden/README.md +46 -0
- package/dist/node_modules/@elysiajs/eden/eden/bunfig.toml +2 -0
- package/dist/node_modules/@elysiajs/eden/eden/dist/chunk-2IHGLN7W.mjs +1 -0
- package/dist/node_modules/@elysiajs/eden/eden/dist/chunk-7WO4HTSU.mjs +1 -0
- package/dist/node_modules/@elysiajs/eden/eden/dist/chunk-XYW4OUFN.mjs +1 -0
- package/dist/node_modules/@elysiajs/eden/eden/dist/chunk-YAG46HFR.mjs +1 -0
- package/dist/node_modules/@elysiajs/eden/eden/dist/errors.d.ts +5 -0
- package/dist/node_modules/@elysiajs/eden/eden/dist/fetch/index.d.ts +4 -0
- package/dist/node_modules/@elysiajs/eden/eden/dist/fetch/types.d.ts +44 -0
- package/dist/node_modules/@elysiajs/eden/eden/dist/fetch.d.mts +48 -0
- package/dist/node_modules/@elysiajs/eden/eden/dist/fetch.d.ts +48 -0
- package/dist/node_modules/@elysiajs/eden/eden/dist/fetch.global.js +1 -0
- package/dist/node_modules/@elysiajs/eden/eden/dist/fetch.js +1 -0
- package/dist/node_modules/@elysiajs/eden/eden/dist/fetch.mjs +1 -0
- package/dist/node_modules/@elysiajs/eden/eden/dist/index.d.mts +5 -0
- package/dist/node_modules/@elysiajs/eden/eden/dist/index.d.ts +5 -0
- package/dist/node_modules/@elysiajs/eden/eden/dist/index.global.js +1 -0
- package/dist/node_modules/@elysiajs/eden/eden/dist/index.js +1 -0
- package/dist/node_modules/@elysiajs/eden/eden/dist/index.mjs +1 -0
- package/dist/node_modules/@elysiajs/eden/eden/dist/treaty/index.d.ts +17 -0
- package/dist/node_modules/@elysiajs/eden/eden/dist/treaty/types.d.ts +99 -0
- package/dist/node_modules/@elysiajs/eden/eden/dist/treaty/utils.d.ts +1 -0
- package/dist/node_modules/@elysiajs/eden/eden/dist/treaty.d.mts +114 -0
- package/dist/node_modules/@elysiajs/eden/eden/dist/treaty.d.ts +114 -0
- package/dist/node_modules/@elysiajs/eden/eden/dist/treaty.global.js +1 -0
- package/dist/node_modules/@elysiajs/eden/eden/dist/treaty.js +1 -0
- package/dist/node_modules/@elysiajs/eden/eden/dist/treaty.mjs +1 -0
- package/dist/node_modules/@elysiajs/eden/eden/dist/treaty2/index.d.ts +5 -0
- package/dist/node_modules/@elysiajs/eden/eden/dist/treaty2/types.d.ts +86 -0
- package/dist/node_modules/@elysiajs/eden/eden/dist/treaty2/ws.d.ts +14 -0
- package/dist/node_modules/@elysiajs/eden/eden/dist/treaty2.d.mts +103 -0
- package/dist/node_modules/@elysiajs/eden/eden/dist/treaty2.d.ts +103 -0
- package/dist/node_modules/@elysiajs/eden/eden/dist/treaty2.global.js +1 -0
- package/dist/node_modules/@elysiajs/eden/eden/dist/treaty2.js +1 -0
- package/dist/node_modules/@elysiajs/eden/eden/dist/treaty2.mjs +1 -0
- package/dist/node_modules/@elysiajs/eden/eden/dist/types-C41kuZ-K.d.mts +44 -0
- package/dist/node_modules/@elysiajs/eden/eden/dist/types-C41kuZ-K.d.ts +44 -0
- package/dist/node_modules/@elysiajs/eden/eden/dist/types.d.ts +39 -0
- package/dist/node_modules/@elysiajs/eden/eden/dist/utils/parsingUtils.d.ts +6 -0
- package/dist/node_modules/@elysiajs/eden/eden/package.json +85 -0
- package/dist/package.json +2 -2
- package/dist/src/backgroundJobs/index.js +44 -0
- package/dist/src/backgroundJobs/jobs/campaignsCacheUpdater.js +160 -0
- package/dist/src/backgroundJobs/jobs/health.js +15 -0
- package/dist/src/backgroundJobs/jobs/opportunityUpdater.js +63 -0
- package/dist/src/backgroundJobs/jobs/priceUpdater.js +16 -0
- package/dist/src/backgroundJobs/jobs/sync.js +33 -0
- package/dist/src/cache/declaration.js +146 -0
- package/dist/src/cache/index.js +152 -0
- package/dist/src/cache/redis.js +49 -0
- package/dist/src/constants.js +119 -0
- package/dist/src/entities/campaign.js +134 -0
- package/dist/src/entities/opportunity.js +549 -0
- package/dist/src/errors/BadRequest.error.js +7 -0
- package/dist/src/errors/Conflict.error.js +7 -0
- package/dist/src/errors/HttpError.js +11 -0
- package/dist/src/errors/NotFound.error.js +7 -0
- package/dist/src/errors/Opportunity.error.js +11 -0
- package/dist/src/errors/Unauthorized.error.js +7 -0
- package/dist/src/errors/index.js +5 -0
- package/dist/src/guards/BackOffice.guard.js +10 -0
- package/dist/src/guards/Engine.guard.js +10 -0
- package/dist/src/guards/TokenAuth.guard.js +10 -0
- package/dist/src/hooks/checkQueryAddressValidity.js +7 -0
- package/dist/src/hooks/checkQueryChainIdValidity.js +7 -0
- package/dist/src/index.js +79 -0
- package/dist/src/internal/controllers/endingCampaigns.js +41 -0
- package/dist/src/internal/controllers/unclaimed.js +36 -0
- package/dist/src/internal/index.js +30 -0
- package/dist/src/libs/campaigns/campaignTypes/AjnaDynamicData.js +111 -0
- package/dist/src/libs/campaigns/campaignTypes/BadgerDynamicData.js +93 -0
- package/dist/src/libs/campaigns/campaignTypes/CLAMMDynamicData.js +942 -0
- package/dist/src/libs/campaigns/campaignTypes/CompoundDynamicData.js +90 -0
- package/dist/src/libs/campaigns/campaignTypes/DolomiteDynamicData.js +60 -0
- package/dist/src/libs/campaigns/campaignTypes/ERC20DynamicData.js +162 -0
- package/dist/src/libs/campaigns/campaignTypes/ERC20DynamicDataRefacto.js +159 -0
- package/dist/src/libs/campaigns/campaignTypes/ERC20SubTypes/helpers/eulerVaultNames.js +13 -0
- package/dist/src/libs/campaigns/campaignTypes/ERC20SubTypes/helpers/factoryFinder.js +29 -0
- package/dist/src/libs/campaigns/campaignTypes/ERC20SubTypes/helpers/getBlacklistedSupply.js +22 -0
- package/dist/src/libs/campaigns/campaignTypes/ERC20SubTypes/helpers/metamorphoTvl.js +35 -0
- package/dist/src/libs/campaigns/campaignTypes/ERC20SubTypes/helpers/spliceTVL.js +21 -0
- package/dist/src/libs/campaigns/campaignTypes/ERC20SubTypes/helpers/tokenType.js +106 -0
- package/dist/src/libs/campaigns/campaignTypes/ERC20SubTypes/processor/AaveProcessor.js +26 -0
- package/dist/src/libs/campaigns/campaignTypes/ERC20SubTypes/processor/AssetProcessor.js +47 -0
- package/dist/src/libs/campaigns/campaignTypes/ERC20SubTypes/processor/AuraProcessor.js +103 -0
- package/dist/src/libs/campaigns/campaignTypes/ERC20SubTypes/processor/BalancerGaugeProcessor.js +83 -0
- package/dist/src/libs/campaigns/campaignTypes/ERC20SubTypes/processor/BalancerPoolProcessor.js +99 -0
- package/dist/src/libs/campaigns/campaignTypes/ERC20SubTypes/processor/BeefyProcessor.js +51 -0
- package/dist/src/libs/campaigns/campaignTypes/ERC20SubTypes/processor/CompoundProcessor.js +36 -0
- package/dist/src/libs/campaigns/campaignTypes/ERC20SubTypes/processor/EnzymeProcessor.js +51 -0
- package/dist/src/libs/campaigns/campaignTypes/ERC20SubTypes/processor/EulerBorrowProcessor.js +46 -0
- package/dist/src/libs/campaigns/campaignTypes/ERC20SubTypes/processor/EulerLendProcessor.js +47 -0
- package/dist/src/libs/campaigns/campaignTypes/ERC20SubTypes/processor/FluidProcessor.js +36 -0
- package/dist/src/libs/campaigns/campaignTypes/ERC20SubTypes/processor/FraxProcessor.js +41 -0
- package/dist/src/libs/campaigns/campaignTypes/ERC20SubTypes/processor/GearboxProcessor.js +44 -0
- package/dist/src/libs/campaigns/campaignTypes/ERC20SubTypes/processor/GenericProcessor.js +239 -0
- package/dist/src/libs/campaigns/campaignTypes/ERC20SubTypes/processor/MetamorphoProcessor.js +43 -0
- package/dist/src/libs/campaigns/campaignTypes/ERC20SubTypes/processor/PendleProcessor.js +31 -0
- package/dist/src/libs/campaigns/campaignTypes/ERC20SubTypes/processor/RadiantProcessor.js +58 -0
- package/dist/src/libs/campaigns/campaignTypes/ERC20SubTypes/processor/RfxProcessor.js +64 -0
- package/dist/src/libs/campaigns/campaignTypes/ERC20SubTypes/processor/SpliceProcessor.js +35 -0
- package/dist/src/libs/campaigns/campaignTypes/ERC20SubTypes/processor/SturdySiloProcessor.js +37 -0
- package/dist/src/libs/campaigns/campaignTypes/ERC20SubTypes/processor/TemplateProcessor.js +40 -0
- package/dist/src/libs/campaigns/campaignTypes/ERC20SubTypes/processor/TorosProcessor.js +33 -0
- package/dist/src/libs/campaigns/campaignTypes/ERC20SubTypes/processor/UniswapProcessor.js +48 -0
- package/dist/src/libs/campaigns/campaignTypes/ERC20SubTypes/processor/WoofiProcessor.js +40 -0
- package/dist/src/libs/campaigns/campaignTypes/ERC20SubTypes/processor/curveProcessor.js +68 -0
- package/dist/src/libs/campaigns/campaignTypes/ERC20SubTypes/processor/processorMapping.js +77 -0
- package/dist/src/libs/campaigns/campaignTypes/ERC20SubTypes/subtypesPrices.js +583 -0
- package/dist/src/libs/campaigns/campaignTypes/ERC20SubTypes/subtypesPricesRefactoFinal.js +24 -0
- package/dist/src/libs/campaigns/campaignTypes/ERC20SubTypes/subtypesRound1.js +1209 -0
- package/dist/src/libs/campaigns/campaignTypes/ERC20SubTypes/subtypesRound1RefactoFinal.js +194 -0
- package/dist/src/libs/campaigns/campaignTypes/ERC20SubTypes/subtypesRound2.js +645 -0
- package/dist/src/libs/campaigns/campaignTypes/ERC20SubTypes/subtypesRound2RefactoFinal.js +22 -0
- package/dist/src/libs/campaigns/campaignTypes/ERC20SubTypes/subtypesRound3.js +392 -0
- package/dist/src/libs/campaigns/campaignTypes/ERC20SubTypes/subtypesRound3RefactoFinal.js +22 -0
- package/dist/src/libs/campaigns/campaignTypes/ERC20SubTypes/subtypesRound4.js +323 -0
- package/dist/src/libs/campaigns/campaignTypes/ERC20SubTypes/subtypesRound4RefactoFinal.js +22 -0
- package/dist/src/libs/campaigns/campaignTypes/ERC20_SNAPSHOTDynamicData.js +38 -0
- package/dist/src/libs/campaigns/campaignTypes/EulerDynamicData.js +165 -0
- package/dist/src/libs/campaigns/campaignTypes/JSON_AIRDROPDynamicData.js +19 -0
- package/dist/src/libs/campaigns/campaignTypes/MORPHODynamicData.js +120 -0
- package/dist/src/libs/campaigns/campaignTypes/RadiantDynamicData.js +112 -0
- package/dist/src/libs/campaigns/campaignTypes/SILODynamicData.js +113 -0
- package/dist/src/libs/campaigns/campaignsDynamicData.js +83 -0
- package/dist/src/libs/campaigns/campaignsDynamicDataRefacto.js +78 -0
- package/dist/src/libs/campaigns/getCampaigns.js +18 -0
- package/dist/src/libs/campaigns/utils/fetchA51Strategies.js +44 -0
- package/dist/src/libs/campaigns/utils/fetchClamInfo.js +27 -0
- package/dist/src/libs/campaigns/utils/fetchLogs.js +91 -0
- package/dist/src/libs/campaigns/utils/getCompV2ForksVaults.js +122 -0
- package/dist/src/libs/campaigns/utils/getContractCreationBlock.js +44 -0
- package/dist/src/libs/campaigns/utils/getDolomiteMarkets.js +50 -0
- package/dist/src/libs/campaigns/utils/getEulerV2Vaults.js +87 -0
- package/dist/src/libs/campaigns/utils/getLastEligibilityRatio.js +56 -0
- package/dist/src/libs/computeFee.js +34 -0
- package/dist/src/libs/custom/twtParticipants.js +54 -0
- package/dist/src/libs/deprecated-merklv3/index.js +184 -0
- package/dist/src/libs/getTokensList.js +37 -0
- package/dist/src/libs/merklChainData.js +129 -0
- package/dist/src/libs/parse/marketsWithCache.js +8 -0
- package/dist/src/libs/positions/ajna/index.js +107 -0
- package/dist/src/libs/positions/badger/index.js +79 -0
- package/dist/src/libs/positions/clamm/index.js +419 -0
- package/dist/src/libs/positions/clamm/thegraph/fetchAlmPositions.js +35 -0
- package/dist/src/libs/positions/clamm/thegraph/fetchAmmPositions.js +35 -0
- package/dist/src/libs/positions/clamm/thegraph/fetchFarmedPositions.js +44 -0
- package/dist/src/libs/positions/clamm/thegraph/index.js +162 -0
- package/dist/src/libs/positions/compound/index.js +93 -0
- package/dist/src/libs/positions/dolomite/index.js +49 -0
- package/dist/src/libs/positions/erc20/index.js +55 -0
- package/dist/src/libs/positions/euler/index.js +57 -0
- package/dist/src/libs/positions/index.js +48 -0
- package/dist/src/libs/positions/morpho/index.js +177 -0
- package/dist/src/libs/positions/prepareFetch.js +339 -0
- package/dist/src/libs/positions/silo/index.js +67 -0
- package/dist/src/libs/positions/types.js +1 -0
- package/dist/src/libs/reports/campaignReport.js +37 -0
- package/dist/src/libs/reports/mainParameterRewards.js +48 -0
- package/dist/src/libs/rewards/userRewards.js +154 -0
- package/dist/src/libs/staticCampaigns.js +10 -0
- package/dist/src/libs/tokens/balances.js +126 -0
- package/dist/src/libs/tokens/tokenInfo.js +22 -0
- package/dist/src/modules/v4/accounting/accounting.controller.js +66 -0
- package/dist/src/modules/v4/accounting/accounting.model.js +32 -0
- package/dist/src/modules/v4/accounting/accounting.repository.js +100 -0
- package/dist/src/modules/v4/accounting/accounting.service.js +78 -0
- package/dist/src/modules/v4/accounting/index.js +3 -0
- package/dist/src/modules/v4/apr/apr.controller.js +1 -0
- package/dist/src/modules/v4/apr/apr.model.js +1 -0
- package/dist/src/modules/v4/apr/apr.repository.js +1 -0
- package/dist/src/modules/v4/apr/apr.service.js +40 -0
- package/dist/src/modules/v4/apr/index.js +2 -0
- package/dist/src/modules/v4/blacklist/blacklist.controller.js +45 -0
- package/dist/src/modules/v4/blacklist/blacklist.model.js +13 -0
- package/dist/src/modules/v4/blacklist/blacklist.repository.js +56 -0
- package/dist/src/modules/v4/blacklist/blacklist.service.js +24 -0
- package/dist/src/modules/v4/blacklist/index.js +3 -0
- package/dist/src/modules/v4/cache/cache.model.js +14 -0
- package/dist/src/modules/v4/cache/cache.repository.js +10 -0
- package/dist/src/modules/v4/cache/cache.service.js +44 -0
- package/dist/src/modules/v4/cache/index.js +1 -0
- package/dist/src/modules/v4/campaign/campaign.controller.js +56 -0
- package/dist/src/modules/v4/campaign/campaign.model.js +54 -0
- package/dist/src/modules/v4/campaign/campaign.repository.js +346 -0
- package/dist/src/modules/v4/campaign/campaign.service.js +203 -0
- package/dist/src/modules/v4/campaign/index.js +3 -0
- package/dist/src/modules/v4/chain/chain.controller.js +40 -0
- package/dist/src/modules/v4/chain/chain.model.js +17 -0
- package/dist/src/modules/v4/chain/chain.repository.js +64 -0
- package/dist/src/modules/v4/chain/chain.service.js +42 -0
- package/dist/src/modules/v4/chain/index.js +3 -0
- package/dist/src/modules/v4/dynamicData/dynamicData.controller.js +19 -0
- package/dist/src/modules/v4/dynamicData/dynamicData.model.js +6 -0
- package/dist/src/modules/v4/dynamicData/dynamicData.repository.js +1 -0
- package/dist/src/modules/v4/dynamicData/dynamicData.service.js +49 -0
- package/dist/src/modules/v4/dynamicData/index.js +3 -0
- package/dist/src/modules/v4/enso/enso.model.js +108 -0
- package/dist/src/modules/v4/enso/enso.service.js +46 -0
- package/dist/src/modules/v4/explorer/explorer.model.js +2 -0
- package/dist/src/modules/v4/explorer/explorer.repository.js +23 -0
- package/dist/src/modules/v4/explorer/explorer.service.js +24 -0
- package/dist/src/modules/v4/explorer/index.js +1 -0
- package/dist/src/modules/v4/index.js +4 -0
- package/dist/src/modules/v4/merklRoot/index.js +3 -0
- package/dist/src/modules/v4/merklRoot/merklRoot.controller.js +19 -0
- package/dist/src/modules/v4/merklRoot/merklRoot.model.js +6 -0
- package/dist/src/modules/v4/merklRoot/merklRoot.repository.js +31 -0
- package/dist/src/modules/v4/merklRoot/merklRoot.service.js +38 -0
- package/dist/src/modules/v4/opportunity/index.js +3 -0
- package/dist/src/modules/v4/opportunity/opportunity.controller.js +69 -0
- package/dist/src/modules/v4/opportunity/opportunity.model.js +36 -0
- package/dist/src/modules/v4/opportunity/opportunity.repository.d.ts +14 -0
- package/dist/src/modules/v4/opportunity/opportunity.repository.js +217 -0
- package/dist/src/modules/v4/opportunity/opportunity.service.d.ts +0 -15
- package/dist/src/modules/v4/opportunity/opportunity.service.js +180 -0
- package/dist/src/modules/v4/opportunity/subservices/getAjnaMetadata.service.js +50 -0
- package/dist/src/modules/v4/opportunity/subservices/getBadgerMetadata.service.js +23 -0
- package/dist/src/modules/v4/opportunity/subservices/getClammMetadata.service.js +33 -0
- package/dist/src/modules/v4/opportunity/subservices/getCompoundMetadata.service.js +18 -0
- package/dist/src/modules/v4/opportunity/subservices/getDolomiteMetadata.service.js +15 -0
- package/dist/src/modules/v4/opportunity/subservices/getErc20Metadata.service.js +63 -0
- package/dist/src/modules/v4/opportunity/subservices/getErc20SnapshotMetadata.service.js +8 -0
- package/dist/src/modules/v4/opportunity/subservices/getEulerMetadata.service.js +30 -0
- package/dist/src/modules/v4/opportunity/subservices/getJsonAirDropMetadata.service.js +36 -0
- package/dist/src/modules/v4/opportunity/subservices/getMorphoMetadata.service.js +19 -0
- package/dist/src/modules/v4/opportunity/subservices/getRadiantMetadata.service.js +9 -0
- package/dist/src/modules/v4/opportunity/subservices/getSiloMetadata.service.js +13 -0
- package/dist/src/modules/v4/opportunity/transform-id.pipe.js +6 -0
- package/dist/src/modules/v4/opportunity/validate-id.pipe.js +12 -0
- package/dist/src/modules/v4/participate/participate.controller.js +66 -0
- package/dist/src/modules/v4/participate/participate.model.js +24 -0
- package/dist/src/modules/v4/participate/participate.service.js +33 -0
- package/dist/src/modules/v4/price/index.js +3 -0
- package/dist/src/modules/v4/price/price.controller.js +62 -0
- package/dist/src/modules/v4/price/price.model.js +12 -0
- package/dist/src/modules/v4/price/price.repository.js +18 -0
- package/dist/src/modules/v4/price/price.service.js +44 -0
- package/dist/src/modules/v4/prisma/index.js +1 -0
- package/dist/src/modules/v4/protocol/index.js +3 -0
- package/dist/src/modules/v4/protocol/protocol.controller.js +23 -0
- package/dist/src/modules/v4/protocol/protocol.model.js +68 -0
- package/dist/src/modules/v4/protocol/protocol.repository.js +37 -0
- package/dist/src/modules/v4/protocol/protocol.service.js +77 -0
- package/dist/src/modules/v4/reward/index.js +3 -0
- package/dist/src/modules/v4/reward/reward.controller.js +52 -0
- package/dist/src/modules/v4/reward/reward.model.js +104 -0
- package/dist/src/modules/v4/reward/reward.repository.js +237 -0
- package/dist/src/modules/v4/reward/reward.service.js +283 -0
- package/dist/src/modules/v4/reward/rewardConvertor.service.js +136 -0
- package/dist/src/modules/v4/router.js +57 -0
- package/dist/src/modules/v4/status/index.js +3 -0
- package/dist/src/modules/v4/status/status.controller.js +48 -0
- package/dist/src/modules/v4/status/status.model.js +24 -0
- package/dist/src/modules/v4/status/status.repository.js +88 -0
- package/dist/src/modules/v4/status/status.service.js +60 -0
- package/dist/src/modules/v4/token/index.js +3 -0
- package/dist/src/modules/v4/token/token.controller.js +32 -0
- package/dist/src/modules/v4/token/token.model.js +23 -0
- package/dist/src/modules/v4/token/token.repository.js +128 -0
- package/dist/src/modules/v4/token/token.service.js +268 -0
- package/dist/src/modules/v4/tvl/index.js +2 -0
- package/dist/src/modules/v4/tvl/tvl.controller.js +1 -0
- package/dist/src/modules/v4/tvl/tvl.model.js +1 -0
- package/dist/src/modules/v4/tvl/tvl.repository.js +1 -0
- package/dist/src/modules/v4/tvl/tvl.service.js +49 -0
- package/dist/src/modules/v4/uniswapV4/index.js +4 -0
- package/dist/src/modules/v4/uniswapV4/uniswapV4.controller.js +11 -0
- package/dist/src/modules/v4/uniswapV4/uniswapV4.model.js +17 -0
- package/dist/src/modules/v4/uniswapV4/uniswapV4.repository.js +2 -0
- package/dist/src/modules/v4/uniswapV4/uniswapV4.service.js +73 -0
- package/dist/src/modules/v4/user/index.js +3 -0
- package/dist/src/modules/v4/user/user.controller.js +69 -0
- package/dist/src/modules/v4/user/user.model.js +18 -0
- package/dist/src/modules/v4/user/user.repository.js +38 -0
- package/dist/src/modules/v4/user/user.service.js +50 -0
- package/dist/src/plugins/error-handling.plugin.js +28 -0
- package/dist/src/plugins/logger.plugin.js +22 -0
- package/dist/src/routes/v1/allowances.js +115 -0
- package/dist/src/routes/v1/balances.js +25 -0
- package/dist/src/routes/v1/prices.js +11 -0
- package/dist/src/routes/v1/tokens.js +17 -0
- package/dist/src/routes/v2/merkl.js +13 -0
- package/dist/src/routes/v3/ERC20Campaigns.js +63 -0
- package/dist/src/routes/v3/app.js +18 -0
- package/dist/src/routes/v3/blacklist.js +18 -0
- package/dist/src/routes/v3/campaign/delay.js +78 -0
- package/dist/src/routes/v3/campaignClaims.js +24 -0
- package/dist/src/routes/v3/campaignReport.js +22 -0
- package/dist/src/routes/v3/campaignUnclaimed.js +28 -0
- package/dist/src/routes/v3/campaigns.js +101 -0
- package/dist/src/routes/v3/campaignsForMainParameter.js +19 -0
- package/dist/src/routes/v3/campaignsInfo.js +54 -0
- package/dist/src/routes/v3/campaignsRewardsReport.js +47 -0
- package/dist/src/routes/v3/claims.js +45 -0
- package/dist/src/routes/v3/compoundV2.js +9 -0
- package/dist/src/routes/v3/createCampaign.js +66 -0
- package/dist/src/routes/v3/dolomite.js +9 -0
- package/dist/src/routes/v3/euler.js +9 -0
- package/dist/src/routes/v3/exports/campaigns.js +28 -0
- package/dist/src/routes/v3/fetch.js +27 -0
- package/dist/src/routes/v3/health.js +13 -0
- package/dist/src/routes/v3/lostyield.js +98 -0
- package/dist/src/routes/v3/merkl.js +119 -0
- package/dist/src/routes/v3/morphoMarkets.js +27 -0
- package/dist/src/routes/v3/morphoVaults.js +22 -0
- package/dist/src/routes/v3/multiChainPositions.js +69 -0
- package/dist/src/routes/v3/opportunity.js +63 -0
- package/dist/src/routes/v3/overview.js +73 -0
- package/dist/src/routes/v3/parse.js +23 -0
- package/dist/src/routes/v3/payload.js +40 -0
- package/dist/src/routes/v3/poolInfo.js +88 -0
- package/dist/src/routes/v3/positions.js +62 -0
- package/dist/src/routes/v3/radiant.js +26 -0
- package/dist/src/routes/v3/recipients.js +20 -0
- package/dist/src/routes/v3/rewards.js +33 -0
- package/dist/src/routes/v3/rewardsReport.js +51 -0
- package/dist/src/routes/v3/rootForTimestamp.js +47 -0
- package/dist/src/routes/v3/silo.js +20 -0
- package/dist/src/routes/v3/token.js +24 -0
- package/dist/src/routes/v3/tokenUnclaimed.js +24 -0
- package/dist/src/routes/v3/twt/participants.js +11 -0
- package/dist/src/routes/v3/updates.js +47 -0
- package/dist/src/routes/v3/userRewards.js +59 -0
- package/dist/src/types/index.js +6 -0
- package/dist/src/types/parameters/Action.js +11 -0
- package/dist/src/types/parameters/Chain.js +13 -0
- package/dist/src/types/parameters/ChainCampaignId.js +13 -0
- package/dist/src/types/parameters/MainParameter.js +19 -0
- package/dist/src/types/parameters/OpportunityId.js +14 -0
- package/dist/src/types/parameters/Timestamp.js +16 -0
- package/dist/src/types/parameters/Type.js +15 -0
- package/dist/src/types/parameters/index.js +17 -0
- package/dist/src/types/returnTypes.js +1 -0
- package/dist/src/types/utils.js +1 -0
- package/dist/src/utils/addString.js +6 -0
- package/dist/src/utils/bigintToString.js +20 -0
- package/dist/src/utils/crypto.js +4 -0
- package/dist/src/utils/decodeCalls.js +170 -0
- package/dist/src/utils/encodeCalls.js +240 -0
- package/dist/src/utils/error.js +90 -0
- package/dist/src/utils/execute.js +41 -0
- package/dist/src/utils/generateCardName.js +89 -0
- package/dist/src/utils/generic.js +117 -0
- package/dist/src/utils/hashArray.js +4 -0
- package/dist/src/utils/lastBlockBefore.js +78 -0
- package/dist/src/utils/logger.js +52 -0
- package/dist/src/utils/pricer.js +180 -0
- package/dist/src/utils/prices/chainlinkRead.js +8 -0
- package/dist/src/utils/prices/curveVirtualPrice.js +7 -0
- package/dist/src/utils/prices/getDQUICK.js +8 -0
- package/dist/src/utils/prices/priceFetcherFactory.js +29 -0
- package/dist/src/utils/prices/priceService.js +328 -0
- package/dist/src/utils/prices/services/coinGeckoService.js +53 -0
- package/dist/src/utils/prices/services/defillamaService.js +53 -0
- package/dist/src/utils/prices/services/dexScreenerService.js +62 -0
- package/dist/src/utils/prices/services/erc4626Service.js +30 -0
- package/dist/src/utils/prices/services/getERC4626.js +11 -0
- package/dist/src/utils/prices/services/indexCoopService.js +55 -0
- package/dist/src/utils/prices/services/priceFetcher.js +1 -0
- package/dist/src/utils/prices/uniV2Price.js +40 -0
- package/dist/src/utils/prisma.js +12 -0
- package/dist/src/utils/providers.js +30 -0
- package/dist/src/utils/queries/activeCampaigns.js +22 -0
- package/dist/src/utils/queries/allCampaigns.js +51 -0
- package/dist/src/utils/queries/campaignsForMainParameter.js +23 -0
- package/dist/src/utils/queries/claimsOverTime.js +111 -0
- package/dist/src/utils/queries/endingCampaigns.js +21 -0
- package/dist/src/utils/queries/futureCampaigns.js +19 -0
- package/dist/src/utils/queries/mainParameterCampaigns.js +11 -0
- package/dist/src/utils/queries/rewardsAmount.js +106 -0
- package/dist/src/utils/queries/unclaimed.js +81 -0
- package/dist/src/utils/rateLimit.js +13 -0
- package/dist/src/utils/stryke.js +4 -0
- package/dist/src/utils/throw.js +27 -0
- package/dist/src/utils/validation.js +20 -0
- package/dist/tsconfig.package.tsbuildinfo +1 -1
- package/package.json +2 -2
@@ -0,0 +1,160 @@
|
|
1
|
+
import { Redis } from "../../cache";
|
2
|
+
import { campaignsToOldFormat } from "../../libs/deprecated-merklv3";
|
3
|
+
import { AprService, CampaignService, OpportunityService } from "../../modules/v4";
|
4
|
+
import { CacheService } from "../../modules/v4/cache";
|
5
|
+
import { TTLPresets } from "../../modules/v4/cache/cache.model";
|
6
|
+
import { OpportunityRepository } from "../../modules/v4/opportunity/opportunity.repository";
|
7
|
+
import { RewardService } from "../../modules/v4/reward";
|
8
|
+
import { TvlService } from "../../modules/v4/tvl";
|
9
|
+
import { engineDbClient } from "../../utils/prisma";
|
10
|
+
import { Campaign, ChainId, NETWORK_LABELS, isSupportedChain, } from "@sdk";
|
11
|
+
import { Elysia, t } from "elysia";
|
12
|
+
import moment from "moment";
|
13
|
+
import { campaignsDynamicData } from "../../libs/campaigns/campaignsDynamicData";
|
14
|
+
import { merklChainData } from "../../libs/merklChainData";
|
15
|
+
import { staticCampaignWithCache } from "../../libs/staticCampaigns";
|
16
|
+
import { InvalidParameter, UnsupportedNetwork } from "../../utils/error";
|
17
|
+
import { executeSimple } from "../../utils/execute";
|
18
|
+
import { log } from "../../utils/logger";
|
19
|
+
import { ALL_CAMPAIGNS_FOR_CHAIN_AFTER } from "../../utils/queries/allCampaigns";
|
20
|
+
const highCampaignsChains = [ChainId.ARBITRUM, ChainId.POLYGON, ChainId.BLAST, ChainId.BASE];
|
21
|
+
export const campaignsCacheUpdater = new Elysia().get("/v3/update", async ({ query, set }) => {
|
22
|
+
const rawChainId = query.chainId;
|
23
|
+
let chainId;
|
24
|
+
if (typeof rawChainId === "string") {
|
25
|
+
chainId = Number.parseInt(rawChainId);
|
26
|
+
if (!isSupportedChain(chainId, "merkl"))
|
27
|
+
throw new UnsupportedNetwork(chainId);
|
28
|
+
}
|
29
|
+
else {
|
30
|
+
throw new InvalidParameter("Invalid chainId provided");
|
31
|
+
}
|
32
|
+
let success = true;
|
33
|
+
try {
|
34
|
+
await Redis.safeSet(`MerklChainData_${chainId}`, await merklChainData(chainId));
|
35
|
+
}
|
36
|
+
catch (error) {
|
37
|
+
log.error(`❌ update merklChainData cache failed for ${NETWORK_LABELS[chainId]}`, error);
|
38
|
+
success = false;
|
39
|
+
}
|
40
|
+
log.local(`🔁 updating ${NETWORK_LABELS[chainId]} Campaigns cache`);
|
41
|
+
let campaignsAfter = moment().subtract(3, "months").unix();
|
42
|
+
if (highCampaignsChains.includes(chainId)) {
|
43
|
+
campaignsAfter = moment().subtract(1, "months").unix();
|
44
|
+
}
|
45
|
+
const TWO_WEEKS_AGO = moment().subtract(2, "weeks").unix();
|
46
|
+
try {
|
47
|
+
const dynamicData = {};
|
48
|
+
let staticData = (await engineDbClient.$queryRaw(ALL_CAMPAIGNS_FOR_CHAIN_AFTER(chainId, campaignsAfter)));
|
49
|
+
log.local(`Data length before filtering: ${staticData.length}`);
|
50
|
+
const mainParameters = {};
|
51
|
+
staticData = staticData.filter(campaign => {
|
52
|
+
if (campaign.endTimestamp < TWO_WEEKS_AGO && campaign.campaignType === Campaign.CLAMM) {
|
53
|
+
campaign.campaignParameters.forwarders = [];
|
54
|
+
}
|
55
|
+
mainParameters[campaign.mainParameter] = true;
|
56
|
+
return true;
|
57
|
+
});
|
58
|
+
log.local(`Data length after filtering: ${staticData.length}`);
|
59
|
+
if (!!staticData) {
|
60
|
+
// Build list of existing campaign types for this chain
|
61
|
+
const campaignTypes = !staticData
|
62
|
+
? []
|
63
|
+
: staticData
|
64
|
+
.map(campaign => campaign.campaignType)
|
65
|
+
.reduce((prev, campaignType) => {
|
66
|
+
if (!prev.includes(campaignType))
|
67
|
+
prev.push(campaignType);
|
68
|
+
return prev;
|
69
|
+
}, []);
|
70
|
+
// Fetch dynamic data for all these types
|
71
|
+
const promisesPerType = campaignTypes.map(async (campaignType) => {
|
72
|
+
const campaigns = staticData.filter(campaign => campaign.campaignType === campaignType);
|
73
|
+
await executeSimple(chainId, campaignsDynamicData(chainId, campaigns, campaignType)).then(r => {
|
74
|
+
for (const d of r) {
|
75
|
+
if (!!d) {
|
76
|
+
// Main Parameter OVERRIDING
|
77
|
+
if (d.campaignType === Campaign.SILO && d.campaignParameters.whitelist?.length === 1) {
|
78
|
+
d.mainParameter = `${d.mainParameter}-${d.campaignParameters.whitelist[0]}`;
|
79
|
+
}
|
80
|
+
if (!dynamicData[`${d.campaignType}_${d.mainParameter}`])
|
81
|
+
dynamicData[`${d.campaignType}_${d.mainParameter}`] = {};
|
82
|
+
dynamicData[`${d.campaignType}_${d.mainParameter}`][d.campaignId] = d;
|
83
|
+
}
|
84
|
+
}
|
85
|
+
});
|
86
|
+
});
|
87
|
+
await Promise.all(promisesPerType);
|
88
|
+
}
|
89
|
+
if (!!dynamicData && Object.keys(dynamicData).length > 0) {
|
90
|
+
await Redis.safeSet(`Campaigns_${chainId}`, dynamicData);
|
91
|
+
// Set live or future campaigns
|
92
|
+
const liveDynamicData = {};
|
93
|
+
for (const [type_mainParameter, value] of Object.entries(dynamicData)) {
|
94
|
+
for (const [campaignId, data] of Object.entries(value)) {
|
95
|
+
if (data.endTimestamp > moment().unix()) {
|
96
|
+
if (!liveDynamicData[type_mainParameter]) {
|
97
|
+
liveDynamicData[type_mainParameter] = {};
|
98
|
+
}
|
99
|
+
liveDynamicData[type_mainParameter][campaignId] = data;
|
100
|
+
}
|
101
|
+
}
|
102
|
+
}
|
103
|
+
await Redis.safeSet(`LiveCampaigns_${chainId}`, liveDynamicData);
|
104
|
+
const merklChainData = await Redis.get("MerklChainData", chainId);
|
105
|
+
await Redis.safeSet(`CampaignsOldFormat_${chainId}`, campaignsToOldFormat(dynamicData, merklChainData));
|
106
|
+
await Redis.safeSet(`LiveCampaignsOldFormat_${chainId}`, campaignsToOldFormat(liveDynamicData, merklChainData));
|
107
|
+
log.info(`✅ ${NETWORK_LABELS[chainId]} caches updated successfully`);
|
108
|
+
for (const entry of Object.entries(liveDynamicData)) {
|
109
|
+
await CampaignService.fill(Object.values(entry[1]).map(({ campaignId, chainId }) => ({
|
110
|
+
campaignId,
|
111
|
+
distributionChain: chainId,
|
112
|
+
})));
|
113
|
+
const [type, mainParameter] = entry[0].split("_");
|
114
|
+
const apr = AprService.extractFromDynamicData(+type, Object.values(entry[1]));
|
115
|
+
const tvl = TvlService.extractFromDynamicData(+type, Object.values(entry[1]));
|
116
|
+
const dailyRewards = await RewardService.extractDailyRewardsRecordFromDynamicData(+type, Object.values(entry[1]));
|
117
|
+
const opportunityId = OpportunityService.hashId({
|
118
|
+
chainId,
|
119
|
+
identifier: mainParameter,
|
120
|
+
type: CampaignService.getTypeFromV3(+type),
|
121
|
+
});
|
122
|
+
await OpportunityRepository.updateRecords(opportunityId, apr, tvl, dailyRewards);
|
123
|
+
}
|
124
|
+
await OpportunityService.updateMetadata(chainId);
|
125
|
+
// ─── Refresh Cache For GET /opportunities ────
|
126
|
+
await CacheService.set(TTLPresets.MIN_5, OpportunityService.getMany, { items: 50, page: 0 });
|
127
|
+
log.info(`✅ ${NETWORK_LABELS[chainId]} DB records updated successfully`);
|
128
|
+
}
|
129
|
+
else {
|
130
|
+
if (chainId === ChainId.CORE || chainId === ChainId.THUNDERCORE) {
|
131
|
+
log.info(`⚠️ no campaigns found for ${NETWORK_LABELS[chainId]}, setting empty cache`);
|
132
|
+
for (const key of [
|
133
|
+
"Campaigns",
|
134
|
+
"LiveCampaigns",
|
135
|
+
"CampaignsOldFormat",
|
136
|
+
"LiveCampaignsOldFormat",
|
137
|
+
]) {
|
138
|
+
await Redis.safeSet(`${key}_${chainId}`, {});
|
139
|
+
}
|
140
|
+
log.info(`✅ ${NETWORK_LABELS[chainId]} caches updated - empty cache`);
|
141
|
+
}
|
142
|
+
}
|
143
|
+
}
|
144
|
+
catch (error) {
|
145
|
+
log.error(`❌ update Campaigns cache failed for ${NETWORK_LABELS[chainId]}`, error);
|
146
|
+
success = false;
|
147
|
+
}
|
148
|
+
// This is independant of campaigns cache update, so not in the if condition
|
149
|
+
try {
|
150
|
+
await staticCampaignWithCache(chainId);
|
151
|
+
}
|
152
|
+
catch (error) {
|
153
|
+
log.error(`❌ update Campaigns cache failed for ${NETWORK_LABELS[chainId]}`, error);
|
154
|
+
}
|
155
|
+
return { success };
|
156
|
+
}, {
|
157
|
+
query: t.Object({
|
158
|
+
chainId: t.String(),
|
159
|
+
}),
|
160
|
+
});
|
@@ -0,0 +1,15 @@
|
|
1
|
+
import { Redis } from "../../cache";
|
2
|
+
import { t } from "elysia";
|
3
|
+
export const response = t.Object({ success: t.Boolean() });
|
4
|
+
export const healthCheck = (app) => {
|
5
|
+
return app.get("/v3/health", async () => {
|
6
|
+
// Check if the cache is working
|
7
|
+
await Redis.get("Prices");
|
8
|
+
return {
|
9
|
+
success: true,
|
10
|
+
};
|
11
|
+
}, {
|
12
|
+
query: t.Object({}),
|
13
|
+
tags: ["Onchain"],
|
14
|
+
});
|
15
|
+
};
|
@@ -0,0 +1,63 @@
|
|
1
|
+
import { Redis } from "../../cache";
|
2
|
+
import { ANGLE_NETWORKS } from "@sdk";
|
3
|
+
import { extractIds, getCampaignsFor, splitCampaigns } from "../../entities/campaign";
|
4
|
+
import { extractOpportunities } from "../../entities/opportunity";
|
5
|
+
import { log } from "../../utils/logger";
|
6
|
+
import { Pricer } from "../../utils/pricer";
|
7
|
+
export const OPPORTUNITY_CACHE = "Opportunities_All";
|
8
|
+
export const OPPORTUNITY_CACHE_TEST = "Opportunities_Test";
|
9
|
+
const reduceOpportunities = async (showTest = false) => {
|
10
|
+
const campaigns = await getCampaignsFor(ANGLE_NETWORKS.merkl.map(c => c));
|
11
|
+
const pricer = await Pricer.load();
|
12
|
+
const opportunityIds = extractIds(campaigns);
|
13
|
+
const opportunityCampaigns = splitCampaigns(campaigns, opportunityIds, showTest);
|
14
|
+
const opportunities = {};
|
15
|
+
for (const { id, ...opportunity } of opportunityCampaigns) {
|
16
|
+
const [_, type, mainParameter] = id.split("_");
|
17
|
+
if (!extractOpportunities[type])
|
18
|
+
continue;
|
19
|
+
const { campaigns: oppCampaigns, ...extracted } = extractOpportunities[type](opportunity?.all?.[0], {
|
20
|
+
all: opportunity?.all ?? [],
|
21
|
+
active: opportunity.active ?? [],
|
22
|
+
inactive: opportunity.inactive ?? [],
|
23
|
+
}, pricer?.prices);
|
24
|
+
opportunities[`${type}_${mainParameter}`] = {
|
25
|
+
...extracted,
|
26
|
+
campaigns: {
|
27
|
+
type: Number.parseInt(type),
|
28
|
+
ids: opportunity?.all?.map(({ campaignId }) => campaignId).filter(c => c),
|
29
|
+
},
|
30
|
+
};
|
31
|
+
}
|
32
|
+
return opportunities;
|
33
|
+
};
|
34
|
+
const getUpdateBreakdown = (opportunities) => {
|
35
|
+
const total = Object.keys(opportunities)?.length;
|
36
|
+
const totalByChain = Object.entries(opportunities).reduce((prev, [_, { chainId }]) => {
|
37
|
+
prev[chainId] += 1;
|
38
|
+
return prev;
|
39
|
+
}, ANGLE_NETWORKS.merkl.reduce((allChains, chain) => Object.assign(allChains, { [chain]: 0 }), {}));
|
40
|
+
const breakdown = Object.entries(totalByChain).reduce((prev, [chain, count]) => {
|
41
|
+
if (count === 0)
|
42
|
+
return prev;
|
43
|
+
prev[chain] = count;
|
44
|
+
return prev;
|
45
|
+
}, {});
|
46
|
+
return { total, breakdown };
|
47
|
+
};
|
48
|
+
export const opportunityUpdater = (app) => {
|
49
|
+
return app.get("/v3/updateOpportunities", async () => {
|
50
|
+
const opportunities = await reduceOpportunities(false);
|
51
|
+
const opportunitiesWithTest = await reduceOpportunities(true);
|
52
|
+
await Redis.safeSet("Opportunities", opportunities);
|
53
|
+
await Redis.safeSet("OpportunitiesWithTest", opportunitiesWithTest);
|
54
|
+
log.info("✅ opportunity cache updated successfully");
|
55
|
+
return new Response(JSON.stringify({
|
56
|
+
status: "success",
|
57
|
+
all: getUpdateBreakdown(opportunities),
|
58
|
+
test: getUpdateBreakdown(opportunitiesWithTest),
|
59
|
+
}), {
|
60
|
+
status: 200,
|
61
|
+
});
|
62
|
+
});
|
63
|
+
};
|
@@ -0,0 +1,16 @@
|
|
1
|
+
import { TokenService } from "../../modules/v4";
|
2
|
+
import { log } from "../../utils/logger";
|
3
|
+
import { Pricer } from "../../utils/pricer";
|
4
|
+
export const priceUpdater = (app) => {
|
5
|
+
return app.get("/v3/updatePrices", async () => {
|
6
|
+
const pricer = await Pricer.load();
|
7
|
+
await pricer.update();
|
8
|
+
log.info("✅ price cache updated successfully");
|
9
|
+
await TokenService.updatePrices(pricer);
|
10
|
+
return new Response(JSON.stringify({
|
11
|
+
status: "success",
|
12
|
+
}), {
|
13
|
+
status: 200,
|
14
|
+
});
|
15
|
+
});
|
16
|
+
};
|
@@ -0,0 +1,33 @@
|
|
1
|
+
import { AuthorizationHeadersDto, EngineGuard } from "../../guards/Engine.guard";
|
2
|
+
import { CampaignService } from "../../modules/v4/campaign";
|
3
|
+
import { ChainService } from "../../modules/v4/chain";
|
4
|
+
import { log } from "../../utils/logger";
|
5
|
+
import Elysia from "elysia";
|
6
|
+
export const sync = new Elysia({ prefix: "/jobs" }).get("/api/sync-with-engine", async () => {
|
7
|
+
const chains = await ChainService.getMany({});
|
8
|
+
for (const chain of chains) {
|
9
|
+
log.info(`fetching campaigns on ${chain.name} (chainId: ${chain.id})`);
|
10
|
+
const campaignsV3 = await CampaignService.getFromEngineDb(chain.id, 0);
|
11
|
+
const campaigns = campaignsV3.map(campaignV3 => {
|
12
|
+
return {
|
13
|
+
amount: campaignV3.amount,
|
14
|
+
campaignId: campaignV3.campaignId,
|
15
|
+
chainId: campaignV3.chainId,
|
16
|
+
computeChainId: campaignV3.computeChainId,
|
17
|
+
creator: campaignV3.creator,
|
18
|
+
endTimestamp: campaignV3.endTimestamp.toString(),
|
19
|
+
opportunityIdentifier: campaignV3.mainParameter,
|
20
|
+
params: JSON.stringify(campaignV3.campaignParameters),
|
21
|
+
rewardTokenAddress: campaignV3.rewardToken,
|
22
|
+
startTimestamp: campaignV3.startTimestamp.toString(),
|
23
|
+
type: campaignV3.campaignType,
|
24
|
+
subType: campaignV3.campaignSubType,
|
25
|
+
};
|
26
|
+
});
|
27
|
+
log.info(`syncing ${campaigns.length} campaigns to sync on ${chain.name}...`);
|
28
|
+
const { success, fail } = await CampaignService.createMany(campaigns);
|
29
|
+
log.info(`${success} campaigns synced successfully on ${chain.name}`);
|
30
|
+
log.info(`${fail} campaigns failed to sync on ${chain.name}`);
|
31
|
+
}
|
32
|
+
return;
|
33
|
+
}, { headers: AuthorizationHeadersDto, beforeHandle: EngineGuard });
|
@@ -0,0 +1,146 @@
|
|
1
|
+
import { TTLType } from "./redis";
|
2
|
+
export const CacheDeclaration = {
|
3
|
+
Updates: { compressed: false, redisTTL: TTLType.Minutes2, localCache: false },
|
4
|
+
Delays: { compressed: false, redisTTL: TTLType.Minutes2, localCache: false },
|
5
|
+
TwtParticipants: { compressed: false, redisTTL: TTLType.Minutes5, localCache: false },
|
6
|
+
CampaignRewards: {
|
7
|
+
compressed: true,
|
8
|
+
redisTTL: TTLType.Hours12,
|
9
|
+
localCache: false,
|
10
|
+
},
|
11
|
+
RewardsMainParameter: {
|
12
|
+
compressed: true,
|
13
|
+
redisTTL: TTLType.Hours12,
|
14
|
+
localCache: false,
|
15
|
+
},
|
16
|
+
RewardsMainParameterDelta: {
|
17
|
+
compressed: true,
|
18
|
+
redisTTL: TTLType.Hours12,
|
19
|
+
localCache: false,
|
20
|
+
},
|
21
|
+
CampaignRewardsDelta: {
|
22
|
+
compressed: true,
|
23
|
+
redisTTL: TTLType.Hours12,
|
24
|
+
localCache: false,
|
25
|
+
},
|
26
|
+
LastBlockBefore: {
|
27
|
+
compressed: false,
|
28
|
+
redisTTL: TTLType.Hours12,
|
29
|
+
localCache: false,
|
30
|
+
},
|
31
|
+
LostYield: {
|
32
|
+
compressed: false,
|
33
|
+
redisTTL: TTLType.Hours3,
|
34
|
+
localCache: false,
|
35
|
+
},
|
36
|
+
DolomiteMarkets: {
|
37
|
+
compressed: false,
|
38
|
+
redisTTL: TTLType.Minutes30,
|
39
|
+
localCache: false,
|
40
|
+
},
|
41
|
+
EulerV2Vaults: {
|
42
|
+
compressed: false,
|
43
|
+
redisTTL: TTLType.Minutes30,
|
44
|
+
localCache: false,
|
45
|
+
},
|
46
|
+
CompoundV2ForksVaults: {
|
47
|
+
compressed: false,
|
48
|
+
redisTTL: TTLType.Week,
|
49
|
+
localCache: false,
|
50
|
+
},
|
51
|
+
RadiantMarkets: {
|
52
|
+
compressed: false,
|
53
|
+
redisTTL: TTLType.Minutes30,
|
54
|
+
localCache: false,
|
55
|
+
},
|
56
|
+
SiloMarkets: {
|
57
|
+
compressed: false,
|
58
|
+
redisTTL: TTLType.Minutes30,
|
59
|
+
localCache: false,
|
60
|
+
},
|
61
|
+
MorphoMarkets: {
|
62
|
+
compressed: false,
|
63
|
+
redisTTL: TTLType.Minutes30,
|
64
|
+
localCache: false,
|
65
|
+
},
|
66
|
+
FarmedPositions: {
|
67
|
+
compressed: false,
|
68
|
+
redisTTL: TTLType.Minutes2,
|
69
|
+
localCache: false,
|
70
|
+
},
|
71
|
+
JsonByTimestamp: {
|
72
|
+
compressed: false,
|
73
|
+
redisTTL: TTLType.Minutes10,
|
74
|
+
localCache: false,
|
75
|
+
},
|
76
|
+
Prices: {
|
77
|
+
compressed: true,
|
78
|
+
redisTTL: TTLType.Minutes30,
|
79
|
+
localCache: false,
|
80
|
+
},
|
81
|
+
MerklChainData: {
|
82
|
+
compressed: false,
|
83
|
+
redisTTL: TTLType.Hours12,
|
84
|
+
localCache: false,
|
85
|
+
},
|
86
|
+
Opportunities: {
|
87
|
+
compressed: true,
|
88
|
+
redisTTL: TTLType.Hours12,
|
89
|
+
localCache: false,
|
90
|
+
},
|
91
|
+
OpportunitiesWithTest: {
|
92
|
+
compressed: true,
|
93
|
+
redisTTL: TTLType.Hours12,
|
94
|
+
localCache: false,
|
95
|
+
},
|
96
|
+
Campaigns: {
|
97
|
+
compressed: true,
|
98
|
+
redisTTL: TTLType.Hours12,
|
99
|
+
localCache: false,
|
100
|
+
},
|
101
|
+
LiveCampaigns: {
|
102
|
+
compressed: true,
|
103
|
+
redisTTL: TTLType.Hours12,
|
104
|
+
localCache: false,
|
105
|
+
},
|
106
|
+
CampaignsOldFormat: {
|
107
|
+
compressed: true,
|
108
|
+
redisTTL: TTLType.Hours12,
|
109
|
+
localCache: false,
|
110
|
+
},
|
111
|
+
LiveCampaignsOldFormat: {
|
112
|
+
compressed: true,
|
113
|
+
redisTTL: TTLType.Hours12,
|
114
|
+
localCache: false,
|
115
|
+
},
|
116
|
+
StaticCampaigns: {
|
117
|
+
compressed: true,
|
118
|
+
redisTTL: TTLType.Hours12,
|
119
|
+
localCache: false,
|
120
|
+
},
|
121
|
+
Blacklist: {
|
122
|
+
compressed: true,
|
123
|
+
redisTTL: TTLType.Minutes10,
|
124
|
+
localCache: false,
|
125
|
+
},
|
126
|
+
TokenList: {
|
127
|
+
compressed: false,
|
128
|
+
redisTTL: TTLType.Minutes30,
|
129
|
+
localCache: false,
|
130
|
+
},
|
131
|
+
CurrentRoot: {
|
132
|
+
compressed: false,
|
133
|
+
redisTTL: TTLType.Seconds30,
|
134
|
+
localCache: true,
|
135
|
+
},
|
136
|
+
Chains: {
|
137
|
+
compressed: false,
|
138
|
+
redisTTL: TTLType.Hours3,
|
139
|
+
localCache: true,
|
140
|
+
},
|
141
|
+
RootsWithRewardOnChain: {
|
142
|
+
compressed: false,
|
143
|
+
redisTTL: TTLType.Minutes2,
|
144
|
+
localCache: true,
|
145
|
+
},
|
146
|
+
};
|
@@ -0,0 +1,152 @@
|
|
1
|
+
import { InvalidCacheCall } from "../utils/error";
|
2
|
+
import { log } from "../utils/logger";
|
3
|
+
import { withRetry, withTimeout } from "@sdk";
|
4
|
+
import NodeCache from "node-cache";
|
5
|
+
import { CacheDeclaration } from "./declaration";
|
6
|
+
import { REDIS_CRON_WRITE_TIMEOUT, REDIS_READ_TIMEOUT, REDIS_RETRIES, redisClient } from "./redis";
|
7
|
+
export class Cache {
|
8
|
+
static decoder = new TextDecoder();
|
9
|
+
static encoder = new TextEncoder();
|
10
|
+
localCache = new NodeCache();
|
11
|
+
/*//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
12
|
+
UTILS
|
13
|
+
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/
|
14
|
+
static baseKey(key) {
|
15
|
+
return key.split("_")[0];
|
16
|
+
}
|
17
|
+
/** @notice Uncompress (if enabled), parsed and typed data from the cache */
|
18
|
+
static uncompress(key, value) {
|
19
|
+
const { compressed } = CacheDeclaration[Cache.baseKey(key)];
|
20
|
+
if (!compressed)
|
21
|
+
return JSON.parse(value);
|
22
|
+
if (!value)
|
23
|
+
return {};
|
24
|
+
const encoded = Buffer.from(value, "base64");
|
25
|
+
const uncompressed = Bun.gunzipSync(encoded);
|
26
|
+
const decoded = Cache.decoder.decode(uncompressed);
|
27
|
+
return JSON.parse(decoded);
|
28
|
+
}
|
29
|
+
/** @notice Compress (if enabled), stringify and encoded data to be stored in the cache */
|
30
|
+
static compress(key, value) {
|
31
|
+
const { compressed } = CacheDeclaration[Cache.baseKey(key)];
|
32
|
+
if (!compressed)
|
33
|
+
return JSON.stringify(value);
|
34
|
+
const encoded = Cache.encoder.encode(JSON.stringify(value));
|
35
|
+
const compressedValue = Bun.gzipSync(encoded);
|
36
|
+
return Buffer.from(compressedValue).toString("base64");
|
37
|
+
}
|
38
|
+
/*//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
39
|
+
REDIS CACHE
|
40
|
+
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/
|
41
|
+
async getRaw(key) {
|
42
|
+
if (!key || key === "")
|
43
|
+
throw new InvalidCacheCall("Trying to access cache with no key");
|
44
|
+
return await withRetry(withTimeout, [redisClient.get(key), REDIS_READ_TIMEOUT], REDIS_RETRIES);
|
45
|
+
}
|
46
|
+
async getManyRaw(keys) {
|
47
|
+
if (keys?.length === 0)
|
48
|
+
throw new InvalidCacheCall("Trying to access cache with no keys");
|
49
|
+
const strippedKeys = Array.from(keys.map(a => a.split("_")[0]).reduce((unique, key) => unique.add(key), new Set()));
|
50
|
+
const multipleCached = await withRetry(withTimeout, [redisClient.mGet(keys), REDIS_READ_TIMEOUT], REDIS_RETRIES);
|
51
|
+
log.local(`Redis: ${keys.length} data fetched with mGet`);
|
52
|
+
return multipleCached;
|
53
|
+
}
|
54
|
+
async setRaw(key, value) {
|
55
|
+
const { redisTTL } = CacheDeclaration[Cache.baseKey(key)];
|
56
|
+
await redisClient.set(key, value, { EX: redisTTL });
|
57
|
+
}
|
58
|
+
/** @notice Set value for a given key for both local and raw cache */
|
59
|
+
async set(key, value) {
|
60
|
+
this.setLocally(key, value);
|
61
|
+
this.setRaw(key, Cache.compress(key, value));
|
62
|
+
}
|
63
|
+
/*//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
64
|
+
LOCAL CACHE
|
65
|
+
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/
|
66
|
+
isLocallyCached(key) {
|
67
|
+
return false;
|
68
|
+
// return this.localCache.has(key);
|
69
|
+
}
|
70
|
+
setLocally(key, value) {
|
71
|
+
return true;
|
72
|
+
// const { localCacheTtl } = CacheDeclaration[Cache.baseKey<T, Key>(key)] as { localCacheTtl?: number };
|
73
|
+
// return this.localCache.set(key, value, localCacheTtl ?? DEFAULT_LOCAL_TTL);
|
74
|
+
}
|
75
|
+
getLocally(key) {
|
76
|
+
return undefined;
|
77
|
+
// return this.localCache.get(key);
|
78
|
+
}
|
79
|
+
/*//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
80
|
+
PUBLIC OPERATIONS
|
81
|
+
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/
|
82
|
+
/**
|
83
|
+
* @returns the uncompressed (if enabled), parsed and typed data from the cache
|
84
|
+
*/
|
85
|
+
async get(key, args) {
|
86
|
+
const actualKey = (args ? `${key}_${args}` : key);
|
87
|
+
if (this.isLocallyCached(actualKey))
|
88
|
+
return this.getLocally(actualKey);
|
89
|
+
const rawCache = await this.getRaw(actualKey);
|
90
|
+
if (rawCache === null)
|
91
|
+
return null;
|
92
|
+
const value = Cache.uncompress(actualKey, rawCache);
|
93
|
+
this.setLocally(actualKey, value);
|
94
|
+
return value;
|
95
|
+
}
|
96
|
+
/**
|
97
|
+
* Get many data from cache
|
98
|
+
* @param key cache key
|
99
|
+
* @returns the uncompressed (if enabled), parsed and typed data from the cache for all keys
|
100
|
+
*/
|
101
|
+
async getMany(keys) {
|
102
|
+
const nonLocalKeys = keys.filter(key => !this.isLocallyCached(key)); // Keys not stored locally
|
103
|
+
const cached = !!nonLocalKeys.length ? await this.getManyRaw(nonLocalKeys) : [];
|
104
|
+
const res = keys.map(key => {
|
105
|
+
if (!nonLocalKeys.includes(key))
|
106
|
+
return this.localCache.get(key);
|
107
|
+
const cachedValue = cached[nonLocalKeys.indexOf(key)];
|
108
|
+
if (cachedValue !== null) {
|
109
|
+
const value = Cache.uncompress(key, cachedValue);
|
110
|
+
this.setLocally(key, value);
|
111
|
+
return value;
|
112
|
+
}
|
113
|
+
return null;
|
114
|
+
});
|
115
|
+
return res;
|
116
|
+
}
|
117
|
+
/**
|
118
|
+
* Get many data from cache with argument
|
119
|
+
* @param key cache key
|
120
|
+
* @param args arguments to append to cache keys
|
121
|
+
* @returns the uncompressed (if enabled), parsed and typed data from the cache for all keys
|
122
|
+
*/
|
123
|
+
async getManyWithArgs(key, args) {
|
124
|
+
const actualKeys = args.map(arg => `${key}_${arg}`);
|
125
|
+
return this.getMany(actualKeys);
|
126
|
+
}
|
127
|
+
/**
|
128
|
+
* Get data from cache or set it using the callback
|
129
|
+
* @param key cache key
|
130
|
+
* @returns the uncompressed (if enabled), parsed and typed data from the cache
|
131
|
+
*/
|
132
|
+
async getOrSet(key, callback, ...args) {
|
133
|
+
if (this.isLocallyCached(key))
|
134
|
+
return this.localCache.get(key);
|
135
|
+
let value;
|
136
|
+
const cachedValue = await this.getRaw(key);
|
137
|
+
if (cachedValue !== null) {
|
138
|
+
value = Cache.uncompress(key, cachedValue);
|
139
|
+
}
|
140
|
+
else {
|
141
|
+
value = await callback(...args);
|
142
|
+
await this.setRaw(key, Cache.compress(key, value));
|
143
|
+
}
|
144
|
+
this.setLocally(key, value);
|
145
|
+
return value;
|
146
|
+
}
|
147
|
+
/** @notice Set with retrials */
|
148
|
+
async safeSet(key, value) {
|
149
|
+
return await withRetry(withTimeout, [this.set(key, value), REDIS_CRON_WRITE_TIMEOUT], REDIS_RETRIES);
|
150
|
+
}
|
151
|
+
}
|
152
|
+
export const Redis = new Cache();
|
@@ -0,0 +1,49 @@
|
|
1
|
+
import { log } from "../utils/logger";
|
2
|
+
import { createClient } from "redis";
|
3
|
+
const REDISHOST = process.env.REDISHOST || "redis";
|
4
|
+
const REDISPORT = !!process.env.REDISPORT ? Number(process.env.REDISPORT) : 6379;
|
5
|
+
const REDISPASSWORD = process.env.REDISPASSWORD || "";
|
6
|
+
export const REDIS_RETRIES = 0;
|
7
|
+
export const REDIS_READ_TIMEOUT = !!process.env.REDIS_READ_TIMEOUT
|
8
|
+
? Number.parseInt(process.env.REDIS_READ_TIMEOUT)
|
9
|
+
: Bun.env.NODE_ENV === "production"
|
10
|
+
? 4_000
|
11
|
+
: 10 * 2_000;
|
12
|
+
export const REDIS_WRITE_TIMEOUT = 4000;
|
13
|
+
export const REDIS_CRON_READ_TIMEOUT = 5000;
|
14
|
+
export const REDIS_CRON_WRITE_TIMEOUT = 10000;
|
15
|
+
export var TTLType;
|
16
|
+
(function (TTLType) {
|
17
|
+
TTLType[TTLType["HalfBlock"] = 4] = "HalfBlock";
|
18
|
+
TTLType[TTLType["Block"] = 11] = "Block";
|
19
|
+
TTLType[TTLType["Seconds30"] = 30] = "Seconds30";
|
20
|
+
TTLType[TTLType["Minutes2"] = 120] = "Minutes2";
|
21
|
+
TTLType[TTLType["Minutes3"] = 180] = "Minutes3";
|
22
|
+
TTLType[TTLType["Minutes5"] = 300] = "Minutes5";
|
23
|
+
TTLType[TTLType["Minutes10"] = 600] = "Minutes10";
|
24
|
+
TTLType[TTLType["Minutes25"] = 1500] = "Minutes25";
|
25
|
+
TTLType[TTLType["Minutes30"] = 1800] = "Minutes30";
|
26
|
+
TTLType[TTLType["Minutes35"] = 2100] = "Minutes35";
|
27
|
+
TTLType[TTLType["Hours3"] = 10800] = "Hours3";
|
28
|
+
TTLType[TTLType["Hours12"] = 43200] = "Hours12";
|
29
|
+
TTLType[TTLType["Day"] = 86400] = "Day";
|
30
|
+
TTLType[TTLType["Week"] = 604800] = "Week";
|
31
|
+
})(TTLType || (TTLType = {}));
|
32
|
+
/** Redis client
|
33
|
+
* @dev About how handling client connections -> https://stackoverflow.com/questions/22387187/node-js-express-redis-when-to-close-connection
|
34
|
+
* @dev Also -> https://github.com/redis/node-redis/issues/568
|
35
|
+
*/
|
36
|
+
const redisConfig = {
|
37
|
+
url: `redis://${REDISHOST}:${REDISPORT}`,
|
38
|
+
socket: REDISHOST === "redis" ? undefined : { tls: true },
|
39
|
+
password: REDISPASSWORD,
|
40
|
+
};
|
41
|
+
export const redisClient = createClient(redisConfig);
|
42
|
+
redisClient.on("error", error => {
|
43
|
+
log.error("Redis", error);
|
44
|
+
});
|
45
|
+
redisClient.connect();
|
46
|
+
redisClient.on("end", () => log.info("Redis: disconnected"));
|
47
|
+
redisClient.on("ready", () => {
|
48
|
+
log.debug("Redis: connected!");
|
49
|
+
});
|