@merkl/api 0.12.2 → 0.12.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,7 @@
1
+ import { Redis } from "../cache";
1
2
  import { redisClient } from "../cache/redis";
3
+ import { getEulerV2Vaults } from "../libs/campaigns/utils/getEulerV2Vaults";
4
+ import { getUniswapV4Pools } from "../libs/campaigns/utils/getUniswapV4Pools";
2
5
  import { DungeonKeeperController } from "../modules/v4/dungeonKeeper";
3
6
  import { log } from "../utils/logger";
4
7
  import { engineDbClient } from "../utils/prisma";
@@ -25,6 +28,12 @@ new Elysia({
25
28
  .use(priceUpdater) // /v3/updatePrices
26
29
  .use(healthCheck) // /v3/health
27
30
  .use(sync) // GET /jobs/api/sync-with-engine
31
+ .get("/eulerUpdate", async () => {
32
+ await Redis.safeSet("EulerV2Vaults", getEulerV2Vaults);
33
+ })
34
+ .get("/uniswapv4Update", async () => {
35
+ await Redis.safeSet("UniswapV4Pools", getUniswapV4Pools);
36
+ })
28
37
  .group("/v4", app => {
29
38
  return app.use(DungeonKeeperController);
30
39
  })
@@ -32,7 +32,7 @@ export declare const CacheDeclaration: {
32
32
  };
33
33
  EulerV2Vaults: {
34
34
  compressed: false;
35
- redisTTL: TTLType.Minutes30;
35
+ redisTTL: TTLType.Hours3;
36
36
  localCache: false;
37
37
  };
38
38
  CompoundV2ForksVaults: {
@@ -20,7 +20,7 @@ export const CacheDeclaration = {
20
20
  },
21
21
  EulerV2Vaults: {
22
22
  compressed: false,
23
- redisTTL: TTLType.Minutes30,
23
+ redisTTL: TTLType.Hours3,
24
24
  localCache: false,
25
25
  },
26
26
  CompoundV2ForksVaults: {
@@ -1,3 +1,4 @@
1
+ import { type RedisFunctions, type RedisModules, type RedisScripts } from "redis";
1
2
  export declare const REDIS_RETRIES = 0;
2
3
  export declare const REDIS_READ_TIMEOUT: number;
3
4
  export declare const REDIS_WRITE_TIMEOUT = 4000;
@@ -308,4 +309,4 @@ export declare const redisClient: import("@redis/client").RedisClientType<{
308
309
  RESERVE: typeof import("@redis/bloom/dist/commands/top-k/RESERVE");
309
310
  reserve: typeof import("@redis/bloom/dist/commands/top-k/RESERVE");
310
311
  };
311
- } & import("redis").RedisModules, import("redis").RedisFunctions, import("redis").RedisScripts>;
312
+ } & RedisModules, RedisFunctions, RedisScripts>;
@@ -1,5 +1,5 @@
1
1
  import { log } from "../utils/logger";
2
- import { createClient } from "redis";
2
+ import { createClient, } from "redis";
3
3
  const REDISHOST = process.env.REDISHOST || "redis";
4
4
  const REDISPORT = !!process.env.REDISPORT ? Number(process.env.REDISPORT) : 6379;
5
5
  const REDISPASSWORD = process.env.REDISPASSWORD || "";
@@ -35,15 +35,22 @@ export var TTLType;
35
35
  */
36
36
  const redisConfig = {
37
37
  url: `redis://${REDISHOST}:${REDISPORT}`,
38
- socket: REDISHOST === "redis" ? undefined : { tls: true },
38
+ socket: REDISHOST === "redis"
39
+ ? undefined
40
+ : {
41
+ tls: true,
42
+ reconnectStrategy: retries => Math.min(retries * 100, 5000),
43
+ keepAlive: 5_000,
44
+ },
39
45
  password: REDISPASSWORD,
40
46
  };
41
47
  export const redisClient = createClient(redisConfig);
42
48
  redisClient.on("error", error => {
43
- log.error("Redis", error);
49
+ log.error("[REDIS]", error);
50
+ redisClient.connect().catch(() => { }); // Auto-reconnect
44
51
  });
45
52
  redisClient.connect();
46
- redisClient.on("end", () => log.info("Redis: disconnected"));
53
+ redisClient.on("end", () => log.debug("[REDIS]: disconnected"));
47
54
  redisClient.on("ready", () => {
48
- log.debug("Redis: connected!");
55
+ log.debug("[REDIS]: connected");
49
56
  });
@@ -64,7 +64,7 @@ const load = async (pendings) => {
64
64
  log.info(`pushing ${pendings.length} pendings`);
65
65
  const { updated, created } = await updatePendings({
66
66
  distributionChainId: chainId,
67
- rewardToken: pendings[0].rewardToken,
67
+ rewardToken: pendings[0].rewardToken, // sometimes undefined
68
68
  campaignId,
69
69
  root,
70
70
  data: pendings,
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,10 @@
1
+ import { TokenService } from "../modules/v4";
2
+ import { log } from "../utils/logger";
3
+ import { Pricer } from "../utils/pricer";
4
+ const pricer = await Pricer.load();
5
+ await pricer.update();
6
+ log.info("✅ Price cache updated successfully!");
7
+ log.info("⏳ Updating API database...");
8
+ await TokenService.updatePrices(pricer);
9
+ log.info("✅ API database updated successfully!");
10
+ process.exit(0);
@@ -18,4 +18,5 @@ export type EulerVaultType = {
18
18
  symbolUnderlying: string;
19
19
  }[];
20
20
  };
21
+ export declare function getEulerV2Vaults(): Promise<EulerVaultType[]>;
21
22
  export declare const getEulerV2VaultsWithCache: () => Promise<EulerVaultType[]>;
@@ -12,7 +12,7 @@ export var LoggedEntityType;
12
12
  LoggedEntityType["EULER"] = "EULER_VAULT";
13
13
  LoggedEntityType["UNISWAP_V4"] = "UNISWAP_V4";
14
14
  })(LoggedEntityType || (LoggedEntityType = {}));
15
- async function getEulerV2Vaults() {
15
+ export async function getEulerV2Vaults() {
16
16
  let vaults = [];
17
17
  // 0_ Fetch all euler vaults from database
18
18
  const storedVaults = await apiDbClient.logged.findMany({
@@ -4,4 +4,5 @@ export type UniswapV4PoolsReturnType = {
4
4
  [poolId: string]: UniswapV4PoolType;
5
5
  };
6
6
  };
7
+ export declare function getUniswapV4Pools(): Promise<UniswapV4PoolsReturnType>;
7
8
  export declare const getUniswapV4PoolsWithCache: () => Promise<UniswapV4PoolsReturnType>;
@@ -2,11 +2,11 @@ import { Redis } from "../../../cache";
2
2
  import { log } from "../../../utils/logger";
3
3
  import { apiDbClient } from "../../../utils/prisma";
4
4
  import { providers } from "../../../utils/providers";
5
- import { ChainInteractionService, ERC20Interface, NETWORK_LABELS, NULL_ADDRESS, PoolManagerInterface, UniswapV4Addresses, getContractCreationBlock, } from "@sdk";
5
+ import { ChainInteractionService, ERC20Interface, NETWORK_LABELS, NULL_ADDRESS, UniswapV4Addresses, UniswapV4PoolManagerInterface, getContractCreationBlock, } from "@sdk";
6
6
  import { safeFetchLogs } from "./fetchLogs";
7
7
  import { LoggedEntityType } from "./getEulerV2Vaults";
8
8
  const UNIV4_CHAINIDS = Object.keys(UniswapV4Addresses).map((x) => Number(x));
9
- async function getUniswapV4Pools() {
9
+ export async function getUniswapV4Pools() {
10
10
  const pools = {};
11
11
  // 0_ Fetch all euler vaults from database
12
12
  const storedPools = await apiDbClient.logged.findMany({
@@ -30,9 +30,9 @@ async function getUniswapV4Pools() {
30
30
  }
31
31
  const toBlock = await jsonRPCprovider.getBlockNumber();
32
32
  const logs = await safeFetchLogs(chainId, // TODO: rm type enforcing
33
- [PoolManagerInterface.getEventTopic("Initialize")], [poolManagerAddress], fromBlock, toBlock);
33
+ [UniswapV4PoolManagerInterface.getEventTopic("Initialize")], [poolManagerAddress], fromBlock, toBlock);
34
34
  const decodedPools = await Promise.all(logs.map(async (log) => {
35
- const [id, currency0, currency1, fee, tickSpacing, hooks] = PoolManagerInterface.decodeEventLog("Initialize", log.data, log.topics);
35
+ const [id, currency0, currency1, fee, tickSpacing, hooks] = UniswapV4PoolManagerInterface.decodeEventLog("Initialize", log.data, log.topics);
36
36
  // Respect typing
37
37
  return {
38
38
  poolId: id,
@@ -5,5 +5,5 @@ export default (app) => app.get("/euler", async () => {
5
5
  return await getEulerV2VaultsWithCache();
6
6
  }, {
7
7
  query: t.Object({}),
8
- tags: ["Protocols"],
8
+ tags: ["euler"],
9
9
  });