@merkl/api 0.10.128 → 0.10.130

Sign up to get free protection for your applications and to get access to all the features.
Files changed (402) hide show
  1. package/dist/database/api/.generated/default.js +1 -0
  2. package/dist/database/api/.generated/edge.js +609 -0
  3. package/dist/database/api/.generated/index-browser.js +586 -0
  4. package/dist/database/api/.generated/index.js +638 -0
  5. package/dist/database/api/.generated/runtime/edge-esm.js +31 -0
  6. package/dist/database/api/.generated/runtime/edge.js +31 -0
  7. package/dist/database/api/.generated/runtime/index-browser.js +13 -0
  8. package/dist/database/api/.generated/runtime/library.js +143 -0
  9. package/dist/database/api/.generated/runtime/react-native.js +80 -0
  10. package/dist/database/api/.generated/runtime/wasm.js +32 -0
  11. package/dist/database/api/.generated/wasm.js +586 -0
  12. package/dist/database/api/seeder/resources/protocol.js +341 -0
  13. package/dist/database/engine/.generated/default.js +1 -0
  14. package/dist/database/engine/.generated/edge.js +438 -0
  15. package/dist/database/engine/.generated/index-browser.js +415 -0
  16. package/dist/database/engine/.generated/index.js +467 -0
  17. package/dist/database/engine/.generated/runtime/edge-esm.js +31 -0
  18. package/dist/database/engine/.generated/runtime/edge.js +31 -0
  19. package/dist/database/engine/.generated/runtime/index-browser.js +13 -0
  20. package/dist/database/engine/.generated/runtime/library.js +143 -0
  21. package/dist/database/engine/.generated/runtime/react-native.js +80 -0
  22. package/dist/database/engine/.generated/runtime/wasm.js +32 -0
  23. package/dist/database/engine/.generated/wasm.js +415 -0
  24. package/dist/node_modules/@elysiajs/eden/eden/LICENSE +7 -0
  25. package/dist/node_modules/@elysiajs/eden/eden/README.md +46 -0
  26. package/dist/node_modules/@elysiajs/eden/eden/bunfig.toml +2 -0
  27. package/dist/node_modules/@elysiajs/eden/eden/dist/chunk-2IHGLN7W.mjs +1 -0
  28. package/dist/node_modules/@elysiajs/eden/eden/dist/chunk-7WO4HTSU.mjs +1 -0
  29. package/dist/node_modules/@elysiajs/eden/eden/dist/chunk-XYW4OUFN.mjs +1 -0
  30. package/dist/node_modules/@elysiajs/eden/eden/dist/chunk-YAG46HFR.mjs +1 -0
  31. package/dist/node_modules/@elysiajs/eden/eden/dist/errors.d.ts +5 -0
  32. package/dist/node_modules/@elysiajs/eden/eden/dist/fetch/index.d.ts +4 -0
  33. package/dist/node_modules/@elysiajs/eden/eden/dist/fetch/types.d.ts +44 -0
  34. package/dist/node_modules/@elysiajs/eden/eden/dist/fetch.d.mts +48 -0
  35. package/dist/node_modules/@elysiajs/eden/eden/dist/fetch.d.ts +48 -0
  36. package/dist/node_modules/@elysiajs/eden/eden/dist/fetch.global.js +1 -0
  37. package/dist/node_modules/@elysiajs/eden/eden/dist/fetch.js +1 -0
  38. package/dist/node_modules/@elysiajs/eden/eden/dist/fetch.mjs +1 -0
  39. package/dist/node_modules/@elysiajs/eden/eden/dist/index.d.mts +5 -0
  40. package/dist/node_modules/@elysiajs/eden/eden/dist/index.d.ts +5 -0
  41. package/dist/node_modules/@elysiajs/eden/eden/dist/index.global.js +1 -0
  42. package/dist/node_modules/@elysiajs/eden/eden/dist/index.js +1 -0
  43. package/dist/node_modules/@elysiajs/eden/eden/dist/index.mjs +1 -0
  44. package/dist/node_modules/@elysiajs/eden/eden/dist/treaty/index.d.ts +17 -0
  45. package/dist/node_modules/@elysiajs/eden/eden/dist/treaty/types.d.ts +99 -0
  46. package/dist/node_modules/@elysiajs/eden/eden/dist/treaty/utils.d.ts +1 -0
  47. package/dist/node_modules/@elysiajs/eden/eden/dist/treaty.d.mts +114 -0
  48. package/dist/node_modules/@elysiajs/eden/eden/dist/treaty.d.ts +114 -0
  49. package/dist/node_modules/@elysiajs/eden/eden/dist/treaty.global.js +1 -0
  50. package/dist/node_modules/@elysiajs/eden/eden/dist/treaty.js +1 -0
  51. package/dist/node_modules/@elysiajs/eden/eden/dist/treaty.mjs +1 -0
  52. package/dist/node_modules/@elysiajs/eden/eden/dist/treaty2/index.d.ts +5 -0
  53. package/dist/node_modules/@elysiajs/eden/eden/dist/treaty2/types.d.ts +86 -0
  54. package/dist/node_modules/@elysiajs/eden/eden/dist/treaty2/ws.d.ts +14 -0
  55. package/dist/node_modules/@elysiajs/eden/eden/dist/treaty2.d.mts +103 -0
  56. package/dist/node_modules/@elysiajs/eden/eden/dist/treaty2.d.ts +103 -0
  57. package/dist/node_modules/@elysiajs/eden/eden/dist/treaty2.global.js +1 -0
  58. package/dist/node_modules/@elysiajs/eden/eden/dist/treaty2.js +1 -0
  59. package/dist/node_modules/@elysiajs/eden/eden/dist/treaty2.mjs +1 -0
  60. package/dist/node_modules/@elysiajs/eden/eden/dist/types-C41kuZ-K.d.mts +44 -0
  61. package/dist/node_modules/@elysiajs/eden/eden/dist/types-C41kuZ-K.d.ts +44 -0
  62. package/dist/node_modules/@elysiajs/eden/eden/dist/types.d.ts +39 -0
  63. package/dist/node_modules/@elysiajs/eden/eden/dist/utils/parsingUtils.d.ts +6 -0
  64. package/dist/node_modules/@elysiajs/eden/eden/package.json +85 -0
  65. package/dist/package.json +2 -2
  66. package/dist/src/backgroundJobs/index.js +44 -0
  67. package/dist/src/backgroundJobs/jobs/campaignsCacheUpdater.js +160 -0
  68. package/dist/src/backgroundJobs/jobs/health.js +15 -0
  69. package/dist/src/backgroundJobs/jobs/opportunityUpdater.js +63 -0
  70. package/dist/src/backgroundJobs/jobs/priceUpdater.js +16 -0
  71. package/dist/src/backgroundJobs/jobs/sync.js +33 -0
  72. package/dist/src/cache/declaration.js +146 -0
  73. package/dist/src/cache/index.js +152 -0
  74. package/dist/src/cache/redis.js +49 -0
  75. package/dist/src/constants.js +119 -0
  76. package/dist/src/entities/campaign.js +134 -0
  77. package/dist/src/entities/opportunity.js +549 -0
  78. package/dist/src/errors/BadRequest.error.js +7 -0
  79. package/dist/src/errors/Conflict.error.js +7 -0
  80. package/dist/src/errors/HttpError.js +11 -0
  81. package/dist/src/errors/NotFound.error.js +7 -0
  82. package/dist/src/errors/Opportunity.error.js +11 -0
  83. package/dist/src/errors/Unauthorized.error.js +7 -0
  84. package/dist/src/errors/index.js +5 -0
  85. package/dist/src/guards/BackOffice.guard.js +10 -0
  86. package/dist/src/guards/Engine.guard.js +10 -0
  87. package/dist/src/guards/TokenAuth.guard.js +10 -0
  88. package/dist/src/hooks/checkQueryAddressValidity.js +7 -0
  89. package/dist/src/hooks/checkQueryChainIdValidity.js +7 -0
  90. package/dist/src/index.js +79 -0
  91. package/dist/src/internal/controllers/endingCampaigns.js +41 -0
  92. package/dist/src/internal/controllers/unclaimed.js +36 -0
  93. package/dist/src/internal/index.js +30 -0
  94. package/dist/src/libs/campaigns/campaignTypes/AjnaDynamicData.js +111 -0
  95. package/dist/src/libs/campaigns/campaignTypes/BadgerDynamicData.js +93 -0
  96. package/dist/src/libs/campaigns/campaignTypes/CLAMMDynamicData.js +942 -0
  97. package/dist/src/libs/campaigns/campaignTypes/CompoundDynamicData.js +90 -0
  98. package/dist/src/libs/campaigns/campaignTypes/DolomiteDynamicData.js +60 -0
  99. package/dist/src/libs/campaigns/campaignTypes/ERC20DynamicData.js +162 -0
  100. package/dist/src/libs/campaigns/campaignTypes/ERC20DynamicDataRefacto.js +159 -0
  101. package/dist/src/libs/campaigns/campaignTypes/ERC20SubTypes/helpers/eulerVaultNames.js +13 -0
  102. package/dist/src/libs/campaigns/campaignTypes/ERC20SubTypes/helpers/factoryFinder.js +29 -0
  103. package/dist/src/libs/campaigns/campaignTypes/ERC20SubTypes/helpers/getBlacklistedSupply.js +22 -0
  104. package/dist/src/libs/campaigns/campaignTypes/ERC20SubTypes/helpers/metamorphoTvl.js +35 -0
  105. package/dist/src/libs/campaigns/campaignTypes/ERC20SubTypes/helpers/spliceTVL.js +21 -0
  106. package/dist/src/libs/campaigns/campaignTypes/ERC20SubTypes/helpers/tokenType.js +106 -0
  107. package/dist/src/libs/campaigns/campaignTypes/ERC20SubTypes/processor/AaveProcessor.js +26 -0
  108. package/dist/src/libs/campaigns/campaignTypes/ERC20SubTypes/processor/AssetProcessor.js +47 -0
  109. package/dist/src/libs/campaigns/campaignTypes/ERC20SubTypes/processor/AuraProcessor.js +103 -0
  110. package/dist/src/libs/campaigns/campaignTypes/ERC20SubTypes/processor/BalancerGaugeProcessor.js +83 -0
  111. package/dist/src/libs/campaigns/campaignTypes/ERC20SubTypes/processor/BalancerPoolProcessor.js +99 -0
  112. package/dist/src/libs/campaigns/campaignTypes/ERC20SubTypes/processor/BeefyProcessor.js +51 -0
  113. package/dist/src/libs/campaigns/campaignTypes/ERC20SubTypes/processor/CompoundProcessor.js +36 -0
  114. package/dist/src/libs/campaigns/campaignTypes/ERC20SubTypes/processor/EnzymeProcessor.js +51 -0
  115. package/dist/src/libs/campaigns/campaignTypes/ERC20SubTypes/processor/EulerBorrowProcessor.js +46 -0
  116. package/dist/src/libs/campaigns/campaignTypes/ERC20SubTypes/processor/EulerLendProcessor.js +47 -0
  117. package/dist/src/libs/campaigns/campaignTypes/ERC20SubTypes/processor/FluidProcessor.js +36 -0
  118. package/dist/src/libs/campaigns/campaignTypes/ERC20SubTypes/processor/FraxProcessor.js +41 -0
  119. package/dist/src/libs/campaigns/campaignTypes/ERC20SubTypes/processor/GearboxProcessor.js +44 -0
  120. package/dist/src/libs/campaigns/campaignTypes/ERC20SubTypes/processor/GenericProcessor.js +239 -0
  121. package/dist/src/libs/campaigns/campaignTypes/ERC20SubTypes/processor/MetamorphoProcessor.js +43 -0
  122. package/dist/src/libs/campaigns/campaignTypes/ERC20SubTypes/processor/PendleProcessor.js +31 -0
  123. package/dist/src/libs/campaigns/campaignTypes/ERC20SubTypes/processor/RadiantProcessor.js +58 -0
  124. package/dist/src/libs/campaigns/campaignTypes/ERC20SubTypes/processor/RfxProcessor.js +64 -0
  125. package/dist/src/libs/campaigns/campaignTypes/ERC20SubTypes/processor/SpliceProcessor.js +35 -0
  126. package/dist/src/libs/campaigns/campaignTypes/ERC20SubTypes/processor/SturdySiloProcessor.js +37 -0
  127. package/dist/src/libs/campaigns/campaignTypes/ERC20SubTypes/processor/TemplateProcessor.js +40 -0
  128. package/dist/src/libs/campaigns/campaignTypes/ERC20SubTypes/processor/TorosProcessor.js +33 -0
  129. package/dist/src/libs/campaigns/campaignTypes/ERC20SubTypes/processor/UniswapProcessor.js +48 -0
  130. package/dist/src/libs/campaigns/campaignTypes/ERC20SubTypes/processor/WoofiProcessor.js +40 -0
  131. package/dist/src/libs/campaigns/campaignTypes/ERC20SubTypes/processor/curveProcessor.js +68 -0
  132. package/dist/src/libs/campaigns/campaignTypes/ERC20SubTypes/processor/processorMapping.js +77 -0
  133. package/dist/src/libs/campaigns/campaignTypes/ERC20SubTypes/subtypesPrices.js +583 -0
  134. package/dist/src/libs/campaigns/campaignTypes/ERC20SubTypes/subtypesPricesRefactoFinal.js +24 -0
  135. package/dist/src/libs/campaigns/campaignTypes/ERC20SubTypes/subtypesRound1.js +1209 -0
  136. package/dist/src/libs/campaigns/campaignTypes/ERC20SubTypes/subtypesRound1RefactoFinal.js +194 -0
  137. package/dist/src/libs/campaigns/campaignTypes/ERC20SubTypes/subtypesRound2.js +645 -0
  138. package/dist/src/libs/campaigns/campaignTypes/ERC20SubTypes/subtypesRound2RefactoFinal.js +22 -0
  139. package/dist/src/libs/campaigns/campaignTypes/ERC20SubTypes/subtypesRound3.js +392 -0
  140. package/dist/src/libs/campaigns/campaignTypes/ERC20SubTypes/subtypesRound3RefactoFinal.js +22 -0
  141. package/dist/src/libs/campaigns/campaignTypes/ERC20SubTypes/subtypesRound4.js +323 -0
  142. package/dist/src/libs/campaigns/campaignTypes/ERC20SubTypes/subtypesRound4RefactoFinal.js +22 -0
  143. package/dist/src/libs/campaigns/campaignTypes/ERC20_SNAPSHOTDynamicData.js +38 -0
  144. package/dist/src/libs/campaigns/campaignTypes/EulerDynamicData.js +165 -0
  145. package/dist/src/libs/campaigns/campaignTypes/JSON_AIRDROPDynamicData.js +19 -0
  146. package/dist/src/libs/campaigns/campaignTypes/MORPHODynamicData.js +120 -0
  147. package/dist/src/libs/campaigns/campaignTypes/RadiantDynamicData.js +112 -0
  148. package/dist/src/libs/campaigns/campaignTypes/SILODynamicData.js +113 -0
  149. package/dist/src/libs/campaigns/campaignsDynamicData.js +83 -0
  150. package/dist/src/libs/campaigns/campaignsDynamicDataRefacto.js +78 -0
  151. package/dist/src/libs/campaigns/getCampaigns.js +18 -0
  152. package/dist/src/libs/campaigns/utils/fetchA51Strategies.js +44 -0
  153. package/dist/src/libs/campaigns/utils/fetchClamInfo.js +27 -0
  154. package/dist/src/libs/campaigns/utils/fetchLogs.js +91 -0
  155. package/dist/src/libs/campaigns/utils/getCompV2ForksVaults.js +122 -0
  156. package/dist/src/libs/campaigns/utils/getContractCreationBlock.js +44 -0
  157. package/dist/src/libs/campaigns/utils/getDolomiteMarkets.js +50 -0
  158. package/dist/src/libs/campaigns/utils/getEulerV2Vaults.js +87 -0
  159. package/dist/src/libs/campaigns/utils/getLastEligibilityRatio.js +56 -0
  160. package/dist/src/libs/computeFee.js +34 -0
  161. package/dist/src/libs/custom/twtParticipants.js +54 -0
  162. package/dist/src/libs/deprecated-merklv3/index.js +184 -0
  163. package/dist/src/libs/getTokensList.js +37 -0
  164. package/dist/src/libs/merklChainData.js +129 -0
  165. package/dist/src/libs/parse/marketsWithCache.js +8 -0
  166. package/dist/src/libs/positions/ajna/index.js +107 -0
  167. package/dist/src/libs/positions/badger/index.js +79 -0
  168. package/dist/src/libs/positions/clamm/index.js +419 -0
  169. package/dist/src/libs/positions/clamm/thegraph/fetchAlmPositions.js +35 -0
  170. package/dist/src/libs/positions/clamm/thegraph/fetchAmmPositions.js +35 -0
  171. package/dist/src/libs/positions/clamm/thegraph/fetchFarmedPositions.js +44 -0
  172. package/dist/src/libs/positions/clamm/thegraph/index.js +162 -0
  173. package/dist/src/libs/positions/compound/index.js +93 -0
  174. package/dist/src/libs/positions/dolomite/index.js +49 -0
  175. package/dist/src/libs/positions/erc20/index.js +55 -0
  176. package/dist/src/libs/positions/euler/index.js +57 -0
  177. package/dist/src/libs/positions/index.js +48 -0
  178. package/dist/src/libs/positions/morpho/index.js +177 -0
  179. package/dist/src/libs/positions/prepareFetch.js +339 -0
  180. package/dist/src/libs/positions/silo/index.js +67 -0
  181. package/dist/src/libs/positions/types.js +1 -0
  182. package/dist/src/libs/reports/campaignReport.js +37 -0
  183. package/dist/src/libs/reports/mainParameterRewards.js +48 -0
  184. package/dist/src/libs/rewards/userRewards.js +154 -0
  185. package/dist/src/libs/staticCampaigns.js +10 -0
  186. package/dist/src/libs/tokens/balances.js +126 -0
  187. package/dist/src/libs/tokens/tokenInfo.js +22 -0
  188. package/dist/src/modules/v4/accounting/accounting.controller.js +66 -0
  189. package/dist/src/modules/v4/accounting/accounting.model.js +32 -0
  190. package/dist/src/modules/v4/accounting/accounting.repository.js +100 -0
  191. package/dist/src/modules/v4/accounting/accounting.service.js +78 -0
  192. package/dist/src/modules/v4/accounting/index.js +3 -0
  193. package/dist/src/modules/v4/apr/apr.controller.js +1 -0
  194. package/dist/src/modules/v4/apr/apr.model.js +1 -0
  195. package/dist/src/modules/v4/apr/apr.repository.js +1 -0
  196. package/dist/src/modules/v4/apr/apr.service.js +40 -0
  197. package/dist/src/modules/v4/apr/index.js +2 -0
  198. package/dist/src/modules/v4/blacklist/blacklist.controller.js +45 -0
  199. package/dist/src/modules/v4/blacklist/blacklist.model.js +13 -0
  200. package/dist/src/modules/v4/blacklist/blacklist.repository.js +56 -0
  201. package/dist/src/modules/v4/blacklist/blacklist.service.js +24 -0
  202. package/dist/src/modules/v4/blacklist/index.js +3 -0
  203. package/dist/src/modules/v4/cache/cache.model.js +14 -0
  204. package/dist/src/modules/v4/cache/cache.repository.js +10 -0
  205. package/dist/src/modules/v4/cache/cache.service.js +44 -0
  206. package/dist/src/modules/v4/cache/index.js +1 -0
  207. package/dist/src/modules/v4/campaign/campaign.controller.js +56 -0
  208. package/dist/src/modules/v4/campaign/campaign.model.js +54 -0
  209. package/dist/src/modules/v4/campaign/campaign.repository.js +346 -0
  210. package/dist/src/modules/v4/campaign/campaign.service.js +203 -0
  211. package/dist/src/modules/v4/campaign/index.js +3 -0
  212. package/dist/src/modules/v4/chain/chain.controller.js +40 -0
  213. package/dist/src/modules/v4/chain/chain.model.js +17 -0
  214. package/dist/src/modules/v4/chain/chain.repository.js +64 -0
  215. package/dist/src/modules/v4/chain/chain.service.js +42 -0
  216. package/dist/src/modules/v4/chain/index.js +3 -0
  217. package/dist/src/modules/v4/dynamicData/dynamicData.controller.js +19 -0
  218. package/dist/src/modules/v4/dynamicData/dynamicData.model.js +6 -0
  219. package/dist/src/modules/v4/dynamicData/dynamicData.repository.js +1 -0
  220. package/dist/src/modules/v4/dynamicData/dynamicData.service.js +49 -0
  221. package/dist/src/modules/v4/dynamicData/index.js +3 -0
  222. package/dist/src/modules/v4/enso/enso.model.js +108 -0
  223. package/dist/src/modules/v4/enso/enso.service.js +46 -0
  224. package/dist/src/modules/v4/explorer/explorer.model.js +2 -0
  225. package/dist/src/modules/v4/explorer/explorer.repository.js +23 -0
  226. package/dist/src/modules/v4/explorer/explorer.service.js +24 -0
  227. package/dist/src/modules/v4/explorer/index.js +1 -0
  228. package/dist/src/modules/v4/index.js +4 -0
  229. package/dist/src/modules/v4/merklRoot/index.js +3 -0
  230. package/dist/src/modules/v4/merklRoot/merklRoot.controller.js +19 -0
  231. package/dist/src/modules/v4/merklRoot/merklRoot.model.js +6 -0
  232. package/dist/src/modules/v4/merklRoot/merklRoot.repository.js +31 -0
  233. package/dist/src/modules/v4/merklRoot/merklRoot.service.js +38 -0
  234. package/dist/src/modules/v4/opportunity/index.js +3 -0
  235. package/dist/src/modules/v4/opportunity/opportunity.controller.js +69 -0
  236. package/dist/src/modules/v4/opportunity/opportunity.model.js +36 -0
  237. package/dist/src/modules/v4/opportunity/opportunity.repository.d.ts +14 -0
  238. package/dist/src/modules/v4/opportunity/opportunity.repository.js +217 -0
  239. package/dist/src/modules/v4/opportunity/opportunity.service.d.ts +0 -15
  240. package/dist/src/modules/v4/opportunity/opportunity.service.js +180 -0
  241. package/dist/src/modules/v4/opportunity/subservices/getAjnaMetadata.service.js +50 -0
  242. package/dist/src/modules/v4/opportunity/subservices/getBadgerMetadata.service.js +23 -0
  243. package/dist/src/modules/v4/opportunity/subservices/getClammMetadata.service.js +33 -0
  244. package/dist/src/modules/v4/opportunity/subservices/getCompoundMetadata.service.js +18 -0
  245. package/dist/src/modules/v4/opportunity/subservices/getDolomiteMetadata.service.js +15 -0
  246. package/dist/src/modules/v4/opportunity/subservices/getErc20Metadata.service.js +63 -0
  247. package/dist/src/modules/v4/opportunity/subservices/getErc20SnapshotMetadata.service.js +8 -0
  248. package/dist/src/modules/v4/opportunity/subservices/getEulerMetadata.service.js +30 -0
  249. package/dist/src/modules/v4/opportunity/subservices/getJsonAirDropMetadata.service.js +36 -0
  250. package/dist/src/modules/v4/opportunity/subservices/getMorphoMetadata.service.js +19 -0
  251. package/dist/src/modules/v4/opportunity/subservices/getRadiantMetadata.service.js +9 -0
  252. package/dist/src/modules/v4/opportunity/subservices/getSiloMetadata.service.js +13 -0
  253. package/dist/src/modules/v4/opportunity/transform-id.pipe.js +6 -0
  254. package/dist/src/modules/v4/opportunity/validate-id.pipe.js +12 -0
  255. package/dist/src/modules/v4/participate/participate.controller.js +66 -0
  256. package/dist/src/modules/v4/participate/participate.model.js +24 -0
  257. package/dist/src/modules/v4/participate/participate.service.js +33 -0
  258. package/dist/src/modules/v4/price/index.js +3 -0
  259. package/dist/src/modules/v4/price/price.controller.js +62 -0
  260. package/dist/src/modules/v4/price/price.model.js +12 -0
  261. package/dist/src/modules/v4/price/price.repository.js +18 -0
  262. package/dist/src/modules/v4/price/price.service.js +44 -0
  263. package/dist/src/modules/v4/prisma/index.js +1 -0
  264. package/dist/src/modules/v4/protocol/index.js +3 -0
  265. package/dist/src/modules/v4/protocol/protocol.controller.js +23 -0
  266. package/dist/src/modules/v4/protocol/protocol.model.js +68 -0
  267. package/dist/src/modules/v4/protocol/protocol.repository.js +37 -0
  268. package/dist/src/modules/v4/protocol/protocol.service.js +77 -0
  269. package/dist/src/modules/v4/reward/index.js +3 -0
  270. package/dist/src/modules/v4/reward/reward.controller.js +52 -0
  271. package/dist/src/modules/v4/reward/reward.model.js +104 -0
  272. package/dist/src/modules/v4/reward/reward.repository.js +237 -0
  273. package/dist/src/modules/v4/reward/reward.service.js +283 -0
  274. package/dist/src/modules/v4/reward/rewardConvertor.service.js +136 -0
  275. package/dist/src/modules/v4/router.js +57 -0
  276. package/dist/src/modules/v4/status/index.js +3 -0
  277. package/dist/src/modules/v4/status/status.controller.js +48 -0
  278. package/dist/src/modules/v4/status/status.model.js +24 -0
  279. package/dist/src/modules/v4/status/status.repository.js +88 -0
  280. package/dist/src/modules/v4/status/status.service.js +60 -0
  281. package/dist/src/modules/v4/token/index.js +3 -0
  282. package/dist/src/modules/v4/token/token.controller.js +32 -0
  283. package/dist/src/modules/v4/token/token.model.js +23 -0
  284. package/dist/src/modules/v4/token/token.repository.js +128 -0
  285. package/dist/src/modules/v4/token/token.service.js +268 -0
  286. package/dist/src/modules/v4/tvl/index.js +2 -0
  287. package/dist/src/modules/v4/tvl/tvl.controller.js +1 -0
  288. package/dist/src/modules/v4/tvl/tvl.model.js +1 -0
  289. package/dist/src/modules/v4/tvl/tvl.repository.js +1 -0
  290. package/dist/src/modules/v4/tvl/tvl.service.js +49 -0
  291. package/dist/src/modules/v4/uniswapV4/index.js +4 -0
  292. package/dist/src/modules/v4/uniswapV4/uniswapV4.controller.js +11 -0
  293. package/dist/src/modules/v4/uniswapV4/uniswapV4.model.js +17 -0
  294. package/dist/src/modules/v4/uniswapV4/uniswapV4.repository.js +2 -0
  295. package/dist/src/modules/v4/uniswapV4/uniswapV4.service.js +73 -0
  296. package/dist/src/modules/v4/user/index.js +3 -0
  297. package/dist/src/modules/v4/user/user.controller.js +69 -0
  298. package/dist/src/modules/v4/user/user.model.js +18 -0
  299. package/dist/src/modules/v4/user/user.repository.js +38 -0
  300. package/dist/src/modules/v4/user/user.service.js +50 -0
  301. package/dist/src/plugins/error-handling.plugin.js +28 -0
  302. package/dist/src/plugins/logger.plugin.js +22 -0
  303. package/dist/src/routes/v1/allowances.js +115 -0
  304. package/dist/src/routes/v1/balances.js +25 -0
  305. package/dist/src/routes/v1/prices.js +11 -0
  306. package/dist/src/routes/v1/tokens.js +17 -0
  307. package/dist/src/routes/v2/merkl.js +13 -0
  308. package/dist/src/routes/v3/ERC20Campaigns.js +63 -0
  309. package/dist/src/routes/v3/app.js +18 -0
  310. package/dist/src/routes/v3/blacklist.js +18 -0
  311. package/dist/src/routes/v3/campaign/delay.js +78 -0
  312. package/dist/src/routes/v3/campaignClaims.js +24 -0
  313. package/dist/src/routes/v3/campaignReport.js +22 -0
  314. package/dist/src/routes/v3/campaignUnclaimed.js +28 -0
  315. package/dist/src/routes/v3/campaigns.js +101 -0
  316. package/dist/src/routes/v3/campaignsForMainParameter.js +19 -0
  317. package/dist/src/routes/v3/campaignsInfo.js +54 -0
  318. package/dist/src/routes/v3/campaignsRewardsReport.js +47 -0
  319. package/dist/src/routes/v3/claims.js +45 -0
  320. package/dist/src/routes/v3/compoundV2.js +9 -0
  321. package/dist/src/routes/v3/createCampaign.js +66 -0
  322. package/dist/src/routes/v3/dolomite.js +9 -0
  323. package/dist/src/routes/v3/euler.js +9 -0
  324. package/dist/src/routes/v3/exports/campaigns.js +28 -0
  325. package/dist/src/routes/v3/fetch.js +27 -0
  326. package/dist/src/routes/v3/health.js +13 -0
  327. package/dist/src/routes/v3/lostyield.js +98 -0
  328. package/dist/src/routes/v3/merkl.js +119 -0
  329. package/dist/src/routes/v3/morphoMarkets.js +27 -0
  330. package/dist/src/routes/v3/morphoVaults.js +22 -0
  331. package/dist/src/routes/v3/multiChainPositions.js +69 -0
  332. package/dist/src/routes/v3/opportunity.js +63 -0
  333. package/dist/src/routes/v3/overview.js +73 -0
  334. package/dist/src/routes/v3/parse.js +23 -0
  335. package/dist/src/routes/v3/payload.js +40 -0
  336. package/dist/src/routes/v3/poolInfo.js +88 -0
  337. package/dist/src/routes/v3/positions.js +62 -0
  338. package/dist/src/routes/v3/radiant.js +26 -0
  339. package/dist/src/routes/v3/recipients.js +20 -0
  340. package/dist/src/routes/v3/rewards.js +33 -0
  341. package/dist/src/routes/v3/rewardsReport.js +51 -0
  342. package/dist/src/routes/v3/rootForTimestamp.js +47 -0
  343. package/dist/src/routes/v3/silo.js +20 -0
  344. package/dist/src/routes/v3/token.js +24 -0
  345. package/dist/src/routes/v3/tokenUnclaimed.js +24 -0
  346. package/dist/src/routes/v3/twt/participants.js +11 -0
  347. package/dist/src/routes/v3/updates.js +47 -0
  348. package/dist/src/routes/v3/userRewards.js +59 -0
  349. package/dist/src/types/index.js +6 -0
  350. package/dist/src/types/parameters/Action.js +11 -0
  351. package/dist/src/types/parameters/Chain.js +13 -0
  352. package/dist/src/types/parameters/ChainCampaignId.js +13 -0
  353. package/dist/src/types/parameters/MainParameter.js +19 -0
  354. package/dist/src/types/parameters/OpportunityId.js +14 -0
  355. package/dist/src/types/parameters/Timestamp.js +16 -0
  356. package/dist/src/types/parameters/Type.js +15 -0
  357. package/dist/src/types/parameters/index.js +17 -0
  358. package/dist/src/types/returnTypes.js +1 -0
  359. package/dist/src/types/utils.js +1 -0
  360. package/dist/src/utils/addString.js +6 -0
  361. package/dist/src/utils/bigintToString.js +20 -0
  362. package/dist/src/utils/crypto.js +4 -0
  363. package/dist/src/utils/decodeCalls.js +170 -0
  364. package/dist/src/utils/encodeCalls.js +240 -0
  365. package/dist/src/utils/error.js +90 -0
  366. package/dist/src/utils/execute.js +41 -0
  367. package/dist/src/utils/generateCardName.js +89 -0
  368. package/dist/src/utils/generic.js +117 -0
  369. package/dist/src/utils/hashArray.js +4 -0
  370. package/dist/src/utils/lastBlockBefore.js +78 -0
  371. package/dist/src/utils/logger.js +52 -0
  372. package/dist/src/utils/pricer.js +180 -0
  373. package/dist/src/utils/prices/chainlinkRead.js +8 -0
  374. package/dist/src/utils/prices/curveVirtualPrice.js +7 -0
  375. package/dist/src/utils/prices/getDQUICK.js +8 -0
  376. package/dist/src/utils/prices/priceFetcherFactory.js +29 -0
  377. package/dist/src/utils/prices/priceService.js +328 -0
  378. package/dist/src/utils/prices/services/coinGeckoService.js +53 -0
  379. package/dist/src/utils/prices/services/defillamaService.js +53 -0
  380. package/dist/src/utils/prices/services/dexScreenerService.js +62 -0
  381. package/dist/src/utils/prices/services/erc4626Service.js +30 -0
  382. package/dist/src/utils/prices/services/getERC4626.js +11 -0
  383. package/dist/src/utils/prices/services/indexCoopService.js +55 -0
  384. package/dist/src/utils/prices/services/priceFetcher.js +1 -0
  385. package/dist/src/utils/prices/uniV2Price.js +40 -0
  386. package/dist/src/utils/prisma.js +12 -0
  387. package/dist/src/utils/providers.js +30 -0
  388. package/dist/src/utils/queries/activeCampaigns.js +22 -0
  389. package/dist/src/utils/queries/allCampaigns.js +51 -0
  390. package/dist/src/utils/queries/campaignsForMainParameter.js +23 -0
  391. package/dist/src/utils/queries/claimsOverTime.js +111 -0
  392. package/dist/src/utils/queries/endingCampaigns.js +21 -0
  393. package/dist/src/utils/queries/futureCampaigns.js +19 -0
  394. package/dist/src/utils/queries/mainParameterCampaigns.js +11 -0
  395. package/dist/src/utils/queries/rewardsAmount.js +106 -0
  396. package/dist/src/utils/queries/unclaimed.js +81 -0
  397. package/dist/src/utils/rateLimit.js +13 -0
  398. package/dist/src/utils/stryke.js +4 -0
  399. package/dist/src/utils/throw.js +27 -0
  400. package/dist/src/utils/validation.js +20 -0
  401. package/dist/tsconfig.package.tsbuildinfo +1 -1
  402. package/package.json +2 -2
@@ -0,0 +1,237 @@
1
+ import { apiDbClient } from "../../../utils/prisma";
2
+ import { CampaignService } from "../campaign";
3
+ import { TokenService } from "../token";
4
+ import { UserService } from "../user";
5
+ import { RewardService } from "./reward.service";
6
+ export class RewardRepository {
7
+ static async createManyReward(rewards) {
8
+ const users = rewards.map(reward => {
9
+ return {
10
+ address: reward.recipient,
11
+ tags: [],
12
+ };
13
+ });
14
+ await UserService.createMany(users);
15
+ const rewardsToCreate = rewards.map(reward => {
16
+ const rewardTokenId = TokenService.hashId({ address: reward.rewardToken, chainId: reward.distributionChainId });
17
+ return {
18
+ id: RewardService.hashId(reward.root, reward.recipient, rewardTokenId),
19
+ root: reward.root,
20
+ recipient: reward.recipient,
21
+ rewardTokenId,
22
+ proofs: reward.proofs,
23
+ };
24
+ });
25
+ return await apiDbClient.reward.createMany({
26
+ data: rewardsToCreate,
27
+ });
28
+ }
29
+ static async createManyBreakdown(data) {
30
+ const breakdownsToCreate = [];
31
+ for (const dataPerCampaign of data) {
32
+ const campaignId = CampaignService.hashId({
33
+ distributionChain: dataPerCampaign.distributionChainId,
34
+ campaignId: dataPerCampaign.campaignId,
35
+ });
36
+ dataPerCampaign.breakdowns.map(breakdown => {
37
+ const rewardId = RewardService.hashId(dataPerCampaign.root, breakdown.recipient, TokenService.hashId({ address: dataPerCampaign.rewardToken, chainId: dataPerCampaign.distributionChainId }));
38
+ breakdownsToCreate.push({
39
+ rewardId,
40
+ protocolId: breakdown.protocolId ? breakdown.protocolId : undefined,
41
+ campaignId,
42
+ reason: breakdown.reason ? breakdown.reason : "",
43
+ amount: breakdown.amount,
44
+ claimed: breakdown.claimed,
45
+ pending: breakdown.pending,
46
+ auxiliaryData1: breakdown.auxiliaryData1 ?? "",
47
+ auxiliaryData2: breakdown.auxiliaryData2 ?? "",
48
+ });
49
+ });
50
+ }
51
+ return await apiDbClient.rewardBreakdown.createMany({
52
+ data: breakdownsToCreate,
53
+ });
54
+ }
55
+ static async getByRecipient(recipient, roots, withToken) {
56
+ return await apiDbClient.reward.findMany({
57
+ where: {
58
+ root: {
59
+ in: roots,
60
+ },
61
+ recipient,
62
+ },
63
+ include: {
64
+ Breakdown: {
65
+ include: {
66
+ Campaign: {
67
+ select: {
68
+ campaignId: true,
69
+ Opportunity: {
70
+ include: {
71
+ MainProtocol: true,
72
+ Chain: true,
73
+ Protocols: true,
74
+ Tokens: true,
75
+ },
76
+ },
77
+ },
78
+ },
79
+ },
80
+ },
81
+ RewardToken: withToken
82
+ ? true
83
+ : {
84
+ select: { address: true, chainId: true, symbol: true, decimals: true },
85
+ },
86
+ },
87
+ });
88
+ }
89
+ static async getByChainRecipientToken(recipient, root, tokenId) {
90
+ return await apiDbClient.reward.findUnique({
91
+ where: {
92
+ root_recipient_rewardTokenId: {
93
+ root,
94
+ recipient,
95
+ rewardTokenId: tokenId,
96
+ },
97
+ },
98
+ include: {
99
+ Breakdown: {
100
+ include: {
101
+ Campaign: {
102
+ select: { campaignId: true },
103
+ },
104
+ },
105
+ },
106
+ },
107
+ });
108
+ }
109
+ static async countRewardPerRewardTokenIdAndRoot() {
110
+ return await apiDbClient.reward.groupBy({
111
+ by: ["root", "rewardTokenId"],
112
+ _count: { _all: true },
113
+ });
114
+ }
115
+ static async countRewardBreakdownPerCampaignId() {
116
+ return await apiDbClient.rewardBreakdown.groupBy({
117
+ by: ["campaignId"],
118
+ _count: { _all: true },
119
+ });
120
+ }
121
+ static async updatePendings(rewardTokenId, root, campaignId, toUpdate) {
122
+ return await apiDbClient.$transaction(toUpdate.map(x => {
123
+ return apiDbClient.rewardBreakdown.update({
124
+ where: {
125
+ rewardId_campaignId_reason: {
126
+ rewardId: RewardService.hashId(root, x.recipient, rewardTokenId),
127
+ campaignId: campaignId,
128
+ reason: x.reason,
129
+ },
130
+ },
131
+ data: {
132
+ pending: x.pending,
133
+ reason: x.reason,
134
+ auxiliaryData1: x.auxiliaryData1,
135
+ auxiliaryData2: x.auxiliaryData2,
136
+ },
137
+ });
138
+ }));
139
+ }
140
+ static async createPendings(rewardTokenId, root, campaignId, toCreate) {
141
+ const users = toCreate.map(x => x.recipient);
142
+ await UserService.createMany(users.map(x => ({ address: x, tags: [] })));
143
+ return await apiDbClient.$transaction(toCreate.map(x => {
144
+ const rewardId = RewardService.hashId(root, x.recipient, rewardTokenId);
145
+ return apiDbClient.rewardBreakdown.create({
146
+ data: {
147
+ reason: x.reason,
148
+ amount: "0",
149
+ pending: x.pending,
150
+ claimed: "0",
151
+ Reward: {
152
+ connectOrCreate: {
153
+ where: { id: rewardId },
154
+ create: {
155
+ id: rewardId,
156
+ MerklRoot: { connect: { root } },
157
+ User: { connect: { address: x.recipient } },
158
+ RewardToken: { connect: { id: rewardTokenId } },
159
+ proofs: [],
160
+ },
161
+ },
162
+ },
163
+ Campaign: { connect: { id: campaignId } },
164
+ },
165
+ });
166
+ }));
167
+ }
168
+ static async findManyRootsWithRewardOnChain(chainId) {
169
+ return (await apiDbClient.merklRoot.findMany({
170
+ where: {
171
+ chainId: chainId,
172
+ Rewards: {
173
+ some: {},
174
+ },
175
+ },
176
+ select: {
177
+ root: true,
178
+ },
179
+ })).map(x => x.root);
180
+ }
181
+ static async breakdownForCampaign(root, id, query) {
182
+ const { page: _page, items: _items } = query;
183
+ const page = _page || 0;
184
+ const items = _items || 50;
185
+ const result = await apiDbClient.$queryRawUnsafe(`
186
+ SELECT
187
+ rb."amount",
188
+ rb."reason",
189
+ r."recipient"
190
+ FROM
191
+ "RewardBreakdown" rb
192
+ INNER JOIN
193
+ "Reward" r ON rb."rewardId" = r."id"
194
+ INNER JOIN
195
+ "Campaign" c ON rb."campaignId" = c."id"
196
+ INNER JOIN
197
+ "Token" t ON r."rewardTokenId" = t."id"
198
+ WHERE
199
+ r."root" = $1 AND rb."campaignId" = $2
200
+ ORDER BY
201
+ rb."amount"::numeric DESC
202
+ LIMIT $3
203
+ OFFSET $4
204
+ `, root, id, items, items * page);
205
+ return result;
206
+ }
207
+ static async total(campaignId, root) {
208
+ const totalAmount = await apiDbClient.rewardBreakdown.findMany({
209
+ where: {
210
+ campaignId,
211
+ Reward: {
212
+ root,
213
+ },
214
+ },
215
+ select: {
216
+ amount: true,
217
+ campaignId: true,
218
+ },
219
+ });
220
+ const reducedData = totalAmount.reduce((acc, { amount }) => {
221
+ acc.amount += BigInt(amount);
222
+ return acc;
223
+ }, { campaignId, amount: 0n });
224
+ return reducedData;
225
+ }
226
+ static async count(campaignId, root) {
227
+ const count = await apiDbClient.rewardBreakdown.count({
228
+ where: {
229
+ campaignId,
230
+ Reward: {
231
+ root,
232
+ },
233
+ },
234
+ });
235
+ return { count };
236
+ }
237
+ }
@@ -0,0 +1,283 @@
1
+ import { log } from "../../../utils/logger";
2
+ import { Campaign, DistributorService, NETWORK_LABELS } from "@sdk";
3
+ import moment from "moment";
4
+ import { BlacklistService } from "../blacklist";
5
+ import { CacheService } from "../cache";
6
+ import { TTLPresets } from "../cache/cache.model";
7
+ import { CampaignService } from "../campaign";
8
+ import { ChainService } from "../chain";
9
+ import { MerklRootService } from "../merklRoot";
10
+ import { OpportunityService } from "../opportunity";
11
+ import { TokenService } from "../token";
12
+ import { RewardRepository } from "./reward.repository";
13
+ export class RewardService {
14
+ static hashId(root, recipient, rewardTokenId) {
15
+ return Bun.hash(`${root}${recipient}${rewardTokenId}`).toString();
16
+ }
17
+ static hashDailyRewardsRecordId(opportunityId, timestamp) {
18
+ return Bun.hash(`${opportunityId}${timestamp}`).toString();
19
+ }
20
+ static async createManyReward(rewards) {
21
+ return await RewardRepository.createManyReward(rewards);
22
+ }
23
+ /**
24
+ * Format the reward breakdown to conform to its resource model declaration
25
+ * @param breakdown straight from db
26
+ * @returns a RewardBreakdown model
27
+ */
28
+ static formatBreakdown(breakdown) {
29
+ const { Campaign, id, rewardId, protocolId, ...rest } = breakdown;
30
+ return {
31
+ ...rest,
32
+ campaignId: Campaign.campaignId,
33
+ opportunity: Campaign.Opportunity,
34
+ };
35
+ }
36
+ /**
37
+ * Format the reward to conform to its resource model declaration
38
+ * @param reward straight from db
39
+ * @returns a Reward model
40
+ */
41
+ static format(rewards) {
42
+ return rewards.map(reward => {
43
+ const { Breakdown, RewardToken, id, rewardTokenId, ...rest } = reward;
44
+ const claimed = Breakdown.reduce((sum, { claimed }) => sum + BigInt(claimed), 0n);
45
+ const amount = Breakdown.reduce((sum, { amount }) => sum + BigInt(amount), 0n);
46
+ const pending = Breakdown.reduce((sum, { pending }) => sum + BigInt(pending), 0n);
47
+ return {
48
+ ...rest,
49
+ token: RewardToken,
50
+ breakdowns: Breakdown.map(RewardService.formatBreakdown),
51
+ claimed,
52
+ amount,
53
+ pending,
54
+ };
55
+ });
56
+ }
57
+ static async createManyBreakdown(data) {
58
+ const missingCampaigns = [];
59
+ const foundCampaigns = [];
60
+ for (const dataPerCampaign of data) {
61
+ const campaignUnique = {
62
+ distributionChain: dataPerCampaign.distributionChainId,
63
+ campaignId: dataPerCampaign.campaignId,
64
+ };
65
+ const campaignExists = await CampaignService.checkIfExist(campaignUnique);
66
+ if (!campaignExists) {
67
+ const { success, fail } = await CampaignService.fill([campaignUnique]);
68
+ if (fail === 1 || success !== 1) {
69
+ missingCampaigns.push(CampaignService.hashId(campaignUnique));
70
+ log.warn(`createManyBreakdown - Missing campaign: ${campaignUnique.campaignId} on ${NETWORK_LABELS[campaignUnique.distributionChain]}`);
71
+ continue;
72
+ }
73
+ }
74
+ foundCampaigns.push(CampaignService.hashId(campaignUnique));
75
+ }
76
+ try {
77
+ return await RewardRepository.createManyBreakdown(data.filter(dataPerCampaign => !missingCampaigns.includes(CampaignService.hashId({
78
+ distributionChain: dataPerCampaign.distributionChainId,
79
+ campaignId: dataPerCampaign.campaignId,
80
+ }))));
81
+ }
82
+ catch (e) {
83
+ log.error(`createManyBreakdown - error creating many breakdowns for campaigns ${foundCampaigns.join(", ")}`, e);
84
+ }
85
+ }
86
+ static async getByRecipient(recipient, roots, withToken = false) {
87
+ return await RewardRepository.getByRecipient(recipient, roots, withToken);
88
+ }
89
+ /**
90
+ * Groups a breakdown array by their corresponding opportunities
91
+ * @param breakdowns with campaignIds
92
+ * @returns array of breakdown group, including the opportunity they belong to
93
+ */
94
+ static splitBreakdownByOpportunity(breakdowns) {
95
+ const opportunities = breakdowns.reduce((aux, { opportunity }) => {
96
+ if (!aux.some(o => o.id === opportunity.id))
97
+ aux.push(opportunity);
98
+ return aux;
99
+ }, []);
100
+ if (!opportunities)
101
+ return [];
102
+ return opportunities.map(opportunity => {
103
+ const relatedBreakdowns = breakdowns.filter(b => opportunity.id.includes(b.opportunity.id));
104
+ const formattedOpportunity = OpportunityService.formatResponseBase(opportunity);
105
+ return {
106
+ opportunity: formattedOpportunity,
107
+ claimed: relatedBreakdowns.reduce((total, { claimed }) => total + BigInt(claimed), 0n),
108
+ amount: relatedBreakdowns.reduce((total, { amount }) => total + BigInt(amount), 0n),
109
+ pending: relatedBreakdowns.reduce((total, { pending }) => total + BigInt(pending), 0n),
110
+ auxiliaryData1: relatedBreakdowns[0]?.auxiliaryData1,
111
+ auxiliaryData2: relatedBreakdowns[0]?.auxiliaryData2,
112
+ };
113
+ });
114
+ }
115
+ /**
116
+ * Applies the splitBreakdownByOpportunity function to each rewards in the array
117
+ * @param rewards return type for most of the rewards functions
118
+ * @returns rewards with updated breakdowns, including the opportunity they belong to
119
+ */
120
+ static splitRewardsBreakdownByOpportunity(rewards) {
121
+ return rewards.map(rewardByChain => {
122
+ const rewards = rewardByChain.rewards.map(reward => {
123
+ const breakdowns = RewardService.splitBreakdownByOpportunity(reward.breakdowns);
124
+ return Object.assign(reward, { breakdowns });
125
+ });
126
+ const distributor = DistributorService(rewardByChain.chain.id).address;
127
+ return Object.assign(rewardByChain, { rewards }, { distributor });
128
+ });
129
+ }
130
+ static removeOpportunityFromRewardBreakdown(rewards) {
131
+ return rewards.map(rewardByChain => {
132
+ const rewards = rewardByChain.rewards.map(reward => {
133
+ const breakdowns = reward.breakdowns.map(breakdown => {
134
+ const { opportunity, ...rest } = breakdown;
135
+ return rest;
136
+ });
137
+ return Object.assign(reward, { breakdowns });
138
+ });
139
+ return Object.assign(rewardByChain, { rewards });
140
+ });
141
+ }
142
+ static async findManyRootsOnChain(chainId) {
143
+ return await CacheService.wrap(TTLPresets.MIN_10, RewardRepository.findManyRootsWithRewardOnChain, chainId);
144
+ }
145
+ static async checkLastClaim(chainId, user, roots, rewards) {
146
+ const claims = await DistributorService(chainId).claimedMultiple(user, rewards.map(reward => reward.RewardToken.address));
147
+ const rootsWithRewardOnChain = await RewardService.findManyRootsOnChain(chainId);
148
+ for (const [index, reward] of rewards.entries()) {
149
+ const merklRootClaimedOn = claims[index].merkleRoot;
150
+ // -> claim is on the current root (chainData.merklRoot) -> claimed === accumulated
151
+ if (merklRootClaimedOn === roots.live) {
152
+ for (const breakdown of reward.Breakdown) {
153
+ breakdown.claimed = breakdown.amount; // Set unclaim to 0
154
+ }
155
+ }
156
+ // -> claim is on a tree we have in db -> claimed === accumulated of the rewards of lastTree
157
+ else if (rootsWithRewardOnChain.includes(merklRootClaimedOn)) {
158
+ const lastTreeRewards = await RewardRepository.getByChainRecipientToken(user, merklRootClaimedOn, TokenService.hashId(reward.RewardToken));
159
+ if (!lastTreeRewards)
160
+ continue;
161
+ for (const breakdown of reward.Breakdown) {
162
+ const lastTreeRewardsBreakdown = lastTreeRewards.Breakdown.find(lastTreeBreakdown => lastTreeBreakdown.reason === breakdown.reason &&
163
+ lastTreeBreakdown.Campaign.campaignId === breakdown.Campaign.campaignId);
164
+ if (!lastTreeRewardsBreakdown)
165
+ continue;
166
+ breakdown.claimed = lastTreeRewardsBreakdown.amount;
167
+ }
168
+ }
169
+ }
170
+ return rewards;
171
+ }
172
+ static async getUserRewardsByChain(user, withToken, chainFilter = []) {
173
+ const chains = await ChainService.findMany();
174
+ let chainIds = chains.map(({ id }) => id).filter(id => !chainFilter.length || chainFilter.includes(id));
175
+ /** Check if the user is blacklisted */
176
+ const isBlacklisted = !!(await BlacklistService.isBlacklisted(user));
177
+ const res = [];
178
+ if (isBlacklisted)
179
+ return res;
180
+ /** Fetch current Merkle Roots */
181
+ const merkleRootsPromises = await Promise.allSettled(chainIds.map(chainId => MerklRootService.fetch(chainId)));
182
+ /** Filter out unsuccessful chainIds */
183
+ chainIds = chainIds.filter((_, index) => merkleRootsPromises[index].status === "fulfilled");
184
+ const merkleRoots = merkleRootsPromises
185
+ .filter(({ status }) => status === "fulfilled")
186
+ .map(x => x.value);
187
+ /** Load rewards from api DB */
188
+ const rewards = (await RewardService.getByRecipient(user, merkleRoots.map(({ live }) => live), withToken)).filter(reward => chainIds.includes(reward.RewardToken.chainId));
189
+ const promises = [];
190
+ for (const [index, chainId] of chainIds.entries()) {
191
+ const chain = chains.find(chain => chain.id === chainId);
192
+ if (!chain)
193
+ throw new Error(`Chain ${chainId} not found`);
194
+ const chainRewards = rewards.filter(reward => reward.RewardToken.chainId === chainId);
195
+ /** Check when the last claim happened */
196
+ if (chainRewards.length > 0) {
197
+ promises.push(RewardService.checkLastClaim(chainId, user, merkleRoots[index], chainRewards).then(r => res.push({ chain, rewards: RewardService.format(r) })));
198
+ }
199
+ }
200
+ const settledPromises = await Promise.allSettled(promises);
201
+ for (const promise of settledPromises) {
202
+ if (promise.status === "rejected") {
203
+ log.error("checkLastClaim failed", promise.reason);
204
+ }
205
+ }
206
+ return res;
207
+ }
208
+ static async updatePendings(data) {
209
+ const rewardTokenId = await TokenService.hashId({ address: data.rewardToken, chainId: data.distributionChainId });
210
+ const campaignId = await CampaignService.hashId({
211
+ distributionChain: data.distributionChainId,
212
+ campaignId: data.campaignId,
213
+ });
214
+ try {
215
+ await RewardRepository.updatePendings(rewardTokenId, data.root, campaignId, data.toUpdate);
216
+ }
217
+ catch (e) {
218
+ log.error("Error updating pendings", `rewardTokenId: ${rewardTokenId}, campaignId: ${campaignId}, root: ${data.root}`);
219
+ console.error(e);
220
+ }
221
+ await RewardRepository.createPendings(rewardTokenId, data.root, campaignId, data.toCreate);
222
+ return true;
223
+ }
224
+ static async countAllchains() {
225
+ const rewardPerRewardTokenId = await RewardRepository.countRewardPerRewardTokenIdAndRoot();
226
+ const rewardBreakdownPerCampaignId = await RewardRepository.countRewardBreakdownPerCampaignId();
227
+ const tokenIdToChain = await TokenService.findChains();
228
+ const campaignIdToChain = await CampaignService.findChains();
229
+ const res = {};
230
+ for (const { _count, rewardTokenId, root } of rewardPerRewardTokenId) {
231
+ const chainId = tokenIdToChain[rewardTokenId];
232
+ if (!chainId)
233
+ continue;
234
+ if (!res[NETWORK_LABELS[chainId]])
235
+ res[NETWORK_LABELS[chainId]] = { rewards: {}, breakdown: 0 };
236
+ if (!res[NETWORK_LABELS[chainId]].rewards[root])
237
+ res[NETWORK_LABELS[chainId]].rewards[root] = 0;
238
+ res[NETWORK_LABELS[chainId]].rewards[root] += _count._all;
239
+ }
240
+ for (const { _count, campaignId } of rewardBreakdownPerCampaignId) {
241
+ const chainId = campaignIdToChain[campaignId];
242
+ if (!chainId)
243
+ continue;
244
+ res[NETWORK_LABELS[chainId]].breakdown += _count._all;
245
+ }
246
+ return res;
247
+ }
248
+ static async breakdownForCampaign(query) {
249
+ const root = await MerklRootService.fetch(query.chainId);
250
+ const id = CampaignService.hashId({ distributionChain: query.chainId, campaignId: query.campaignId });
251
+ return RewardRepository.breakdownForCampaign(root.live, id, query);
252
+ }
253
+ static async count(query) {
254
+ const root = await MerklRootService.fetch(query.chainId);
255
+ const id = CampaignService.hashId({ distributionChain: query.chainId, campaignId: query.campaignId });
256
+ return RewardRepository.count(id, root.live);
257
+ }
258
+ static async total(query) {
259
+ const root = await MerklRootService.fetch(query.chainId);
260
+ return RewardRepository.total(CampaignService.hashId({ distributionChain: query.chainId, campaignId: query.campaignId }), root.live);
261
+ }
262
+ static async extractDailyRewardsRecordFromDynamicData(type, dynamicData, timestamp = BigInt(moment().unix())) {
263
+ const typesWithoutApr = [Campaign.INVALID];
264
+ if (typesWithoutApr.includes(type))
265
+ return { timestamp, total: 0, breakdowns: [] };
266
+ const breakdowns = [];
267
+ for (const { amount, rewardToken: address, chainId, startTimestamp: start, endTimestamp: end, campaignId, } of dynamicData) {
268
+ const timespan = Math.abs(end - start);
269
+ const dayspan = Math.max(1, Math.floor(timespan / (60 * 60 * 24)));
270
+ const dailyAmount = BigInt(amount) / BigInt(dayspan);
271
+ const campaignDailyValue = await TokenService.getValue([{ amount: dailyAmount, address, chainId }]);
272
+ breakdowns.push({
273
+ campaignId: CampaignService.hashId({ campaignId, distributionChain: chainId }),
274
+ value: campaignDailyValue,
275
+ });
276
+ }
277
+ return {
278
+ timestamp,
279
+ total: breakdowns.reduce((sum, { value }) => sum + value, 0),
280
+ breakdowns,
281
+ };
282
+ }
283
+ }
@@ -0,0 +1,136 @@
1
+ import { RewardService } from "./reward.service";
2
+ export class RewardConvertorService {
3
+ /**
4
+ * Convert the v4 reward data to the v3 model used in the v3/userRewards route
5
+ */
6
+ static convertV4toUserRewardV3(data, includeProofs = false) {
7
+ const res = {};
8
+ for (const { chain: _chain, rewards } of data) {
9
+ for (const reward of rewards) {
10
+ const { token, breakdowns, proofs } = reward;
11
+ const rewardToken = token.address;
12
+ res[rewardToken] = {
13
+ accumulated: "0",
14
+ decimals: token.decimals,
15
+ symbol: token.symbol,
16
+ unclaimed: "0",
17
+ pending: "0",
18
+ proof: includeProofs ? proofs : undefined,
19
+ reasons: {},
20
+ };
21
+ for (const breakdown of breakdowns) {
22
+ const { amount, claimed, pending, reason } = breakdown;
23
+ if (!res[rewardToken].reasons[reason]) {
24
+ res[rewardToken].reasons[reason] = {
25
+ accumulated: amount,
26
+ unclaimed: (BigInt(amount) - BigInt(claimed)).toString(),
27
+ pending,
28
+ };
29
+ }
30
+ else {
31
+ res[rewardToken].reasons[reason].accumulated = (BigInt(res[rewardToken].reasons[reason].accumulated) + BigInt(amount)).toString();
32
+ res[rewardToken].reasons[reason].unclaimed = (BigInt(res[rewardToken].reasons[reason].unclaimed) +
33
+ BigInt(amount) -
34
+ BigInt(claimed)).toString();
35
+ res[rewardToken].reasons[reason].pending = (BigInt(res[rewardToken].reasons[reason].pending ?? "0") + BigInt(pending)).toString();
36
+ }
37
+ res[rewardToken].accumulated = (BigInt(res[rewardToken].accumulated) + BigInt(amount)).toString();
38
+ res[rewardToken].unclaimed = (BigInt(res[rewardToken].unclaimed) +
39
+ BigInt(amount) -
40
+ BigInt(claimed)).toString();
41
+ res[rewardToken].pending = (BigInt(res[rewardToken].pending ?? "0") + BigInt(pending)).toString();
42
+ }
43
+ }
44
+ }
45
+ return res;
46
+ }
47
+ /**
48
+ * Convert the v4 reward data to the v3 model used in the v3/rewards route
49
+ */
50
+ static convertV4toRewardV3(data) {
51
+ const res = {};
52
+ for (const { chain, rewards } of data) {
53
+ res[chain.id] = {
54
+ campaignData: {},
55
+ tokenData: {},
56
+ };
57
+ for (const reward of rewards) {
58
+ const { token, breakdowns, proofs } = reward;
59
+ const rewardToken = token.address;
60
+ if (!res[chain.id].tokenData[rewardToken]) {
61
+ res[chain.id].tokenData[rewardToken] = {
62
+ accumulated: "0",
63
+ unclaimed: "0",
64
+ pending: "0",
65
+ decimals: token.decimals,
66
+ symbol: token.symbol,
67
+ proof: proofs,
68
+ };
69
+ }
70
+ for (const breakdown of breakdowns) {
71
+ const { amount, claimed, pending, reason, campaignId } = breakdown;
72
+ if (!res[chain.id].campaignData[campaignId]) {
73
+ res[chain.id].campaignData[campaignId] = {};
74
+ }
75
+ if (!res[chain.id].campaignData[campaignId][reason]) {
76
+ res[chain.id].campaignData[campaignId][reason] = {
77
+ accumulated: "0",
78
+ unclaimed: "0",
79
+ pending: "0",
80
+ auxiliaryData1: breakdown.auxiliaryData1 === "" ? "0" : breakdown.auxiliaryData1 ?? "0",
81
+ auxiliaryData2: breakdown.auxiliaryData2 === "" ? "0" : breakdown.auxiliaryData2 ?? "0",
82
+ decimals: token.decimals,
83
+ mainParameter: breakdown.opportunity.identifier,
84
+ symbol: token.symbol,
85
+ token: rewardToken,
86
+ };
87
+ }
88
+ res[chain.id].tokenData[rewardToken].accumulated = (BigInt(res[chain.id].tokenData[rewardToken].accumulated) + BigInt(amount)).toString();
89
+ res[chain.id].tokenData[rewardToken].unclaimed = (BigInt(res[chain.id].tokenData[rewardToken].unclaimed) +
90
+ BigInt(amount) -
91
+ BigInt(claimed)).toString();
92
+ res[chain.id].tokenData[rewardToken].pending = (BigInt(pending ?? "0") + BigInt(pending)).toString();
93
+ res[chain.id].campaignData[campaignId][reason].accumulated = (BigInt(res[chain.id].campaignData[campaignId][reason].accumulated) + BigInt(amount)).toString();
94
+ res[chain.id].campaignData[campaignId][reason].unclaimed = (BigInt(res[chain.id].campaignData[campaignId][reason].unclaimed) +
95
+ BigInt(amount) -
96
+ BigInt(claimed)).toString();
97
+ res[chain.id].campaignData[campaignId][reason].pending = (BigInt(res[chain.id].campaignData[campaignId][reason].pending ?? "0") + BigInt(pending)).toString();
98
+ }
99
+ }
100
+ }
101
+ return res;
102
+ }
103
+ static async convertV4toMerklV2(user, chainId, data) {
104
+ const rewardsV4 = await RewardService.getUserRewardsByChain(user, false, [chainId]);
105
+ if (!!rewardsV4?.[0]?.rewards) {
106
+ const userType = {
107
+ transactionData: rewardsV4[0].rewards.reduce((acc, reward) => {
108
+ acc[reward.token.address] = {
109
+ claim: (BigInt(reward.amount) - BigInt(reward.claimed)).toString(),
110
+ leaf: reward.proofs?.[0],
111
+ proof: reward.proofs,
112
+ token: reward.token.address,
113
+ };
114
+ return acc;
115
+ }, {}),
116
+ };
117
+ data = { ...data, ...userType };
118
+ }
119
+ for (const rewardsPerChain of rewardsV4) {
120
+ for (const reward of rewardsPerChain.rewards) {
121
+ for (const breakdown of reward.breakdowns) {
122
+ const mainParameter = breakdown?.opportunity?.identifier;
123
+ if (!!mainParameter) {
124
+ const campaignIndex = data?.pools?.[mainParameter]?.distributionData?.findIndex(d => d.id === breakdown.campaignId);
125
+ if (campaignIndex >= 0) {
126
+ data.pools[mainParameter].distributionData[campaignIndex].unclaimed =
127
+ (data.pools[mainParameter].distributionData[campaignIndex].unclaimed ?? 0) +
128
+ Number.parseInt((BigInt(reward.amount) - BigInt(reward.claimed)).toString());
129
+ }
130
+ }
131
+ }
132
+ }
133
+ }
134
+ return data;
135
+ }
136
+ }