@merkl/api 0.20.52 → 0.20.54

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.
Files changed (25) hide show
  1. package/dist/src/backgroundJobs/index.js +5 -3
  2. package/dist/src/eden/index.d.ts +280 -91
  3. package/dist/src/engine/dynamicData/factory.js +6 -0
  4. package/dist/src/engine/dynamicData/implementations/Erc20.d.ts +2 -2
  5. package/dist/src/engine/dynamicData/implementations/Erc20.js +16 -2
  6. package/dist/src/engine/dynamicData/implementations/UniswapV4.js +1 -1
  7. package/dist/src/engine/opportunityMetadata/factory.js +6 -0
  8. package/dist/src/engine/opportunityMetadata/implementations/Clamm.js +8 -1
  9. package/dist/src/index.d.ts +72 -15
  10. package/dist/src/jobs/update-uniswap-v4-pools.js +3 -2
  11. package/dist/src/modules/v4/accounting/accounting.repository.js +72 -18
  12. package/dist/src/modules/v4/router.d.ts +72 -15
  13. package/dist/src/modules/v4/uniswap/uniswap.controller.d.ts +72 -15
  14. package/dist/src/modules/v4/uniswap/uniswap.controller.js +49 -6
  15. package/dist/src/modules/v4/uniswap/uniswap.model.d.ts +35 -16
  16. package/dist/src/modules/v4/uniswap/uniswap.model.js +22 -8
  17. package/dist/src/modules/v4/uniswap/uniswap.repository.d.ts +2 -2
  18. package/dist/src/modules/v4/uniswap/uniswap.repository.js +2 -2
  19. package/dist/src/modules/v4/uniswap/uniswap.service.d.ts +4 -19
  20. package/dist/src/modules/v4/uniswap/uniswap.service.js +20 -80
  21. package/dist/src/routes/v3/uniswapv4.js +5 -5
  22. package/dist/tsconfig.package.tsbuildinfo +1 -1
  23. package/package.json +14 -14
  24. package/dist/src/engine/dynamicData/utils/getUniswapV4Pools.d.ts +0 -10
  25. package/dist/src/engine/dynamicData/utils/getUniswapV4Pools.js +0 -188
@@ -1,18 +1,15 @@
1
1
  import { safeFetchLogs } from "@/engine/dynamicData/utils/fetchLogs";
2
- import { batchMulticallCallWithRetry } from "@/utils/generic";
3
2
  import { log } from "@/utils/logger";
4
3
  import { providers } from "@/utils/providers";
5
- import { LoggedEntityType } from "@db/api";
6
- import { ChainInteractionService, ERC20Interface, NETWORK_LABELS, NULL_ADDRESS, UniswapV4Addresses, UniswapV4PoolManagerInterface, UniswapV4PoolManager__factory, getContractCreationBlock, } from "@sdk";
7
- import { utils } from "ethers";
4
+ import { ChainInteractionService, ERC20Interface, NETWORK_LABELS, NULL_ADDRESS, UniswapV4Addresses, UniswapV4PoolManagerInterface, getContractCreationBlock, } from "@sdk";
8
5
  import { getAddress } from "viem";
9
6
  import { BlacklistService } from "../blacklist";
10
7
  import { ChainService } from "../chain/chain.service";
11
8
  import { MerklRootService } from "../merklRoot";
12
9
  import { OpportunityService } from "../opportunity";
13
10
  import { RewardService } from "../reward";
11
+ import { LoggedEntityType, UniV4ChainIdArray, } from "./uniswap.model";
14
12
  import { UniswapRepository } from "./uniswap.repository";
15
- export const PoolManagerInterface = UniswapV4PoolManager__factory.createInterface();
16
13
  export class UniswapService {
17
14
  static async findV3RewardsPerPosition(query) {
18
15
  /** Check if the user is blacklisted */
@@ -52,83 +49,24 @@ export class UniswapService {
52
49
  }
53
50
  return res;
54
51
  }
55
- static async getPoolsByChain(chainId) {
56
- const lastBlock = await providers[chainId].getBlockNumber();
57
- const logs = await safeFetchLogs(chainId, [PoolManagerInterface.getEventTopic("Initialize")], ["0xE8E23e97Fa135823143d6b9Cba9c699040D51F70"], 0, lastBlock);
58
- const poolData = [];
59
- const calls = [];
60
- for (const log of logs) {
61
- const poolId = utils.defaultAbiCoder.decode(["bytes32"], log.topics[1])[0];
62
- const currency0 = utils.defaultAbiCoder.decode(["address"], log.topics[2])[0];
63
- const currency1 = utils.defaultAbiCoder.decode(["address"], log.topics[3])[0];
64
- const [_indexedPoolId, _indexedCurrency0, _indexedCurrency1, fee, tickSpacing, hooks, sqrtPriceX98, tick] = PoolManagerInterface.decodeEventLog("Initialize", log.data, log.topics);
65
- poolData.push({
66
- poolId,
67
- poolKey: {
68
- currency0,
69
- currency1,
70
- fee,
71
- tickSpacing,
72
- hooks,
73
- },
74
- });
75
- calls.push({
76
- allowFailure: true,
77
- callData: ERC20Interface.encodeFunctionData("symbol"),
78
- target: currency0,
79
- }, {
80
- allowFailure: true,
81
- callData: ERC20Interface.encodeFunctionData("decimals"),
82
- target: currency0,
83
- }, {
84
- allowFailure: true,
85
- callData: ERC20Interface.encodeFunctionData("symbol"),
86
- target: currency1,
87
- }, {
88
- allowFailure: true,
89
- callData: ERC20Interface.encodeFunctionData("decimals"),
90
- target: currency1,
91
- });
52
+ static async getUniswapV4Pools(chainId) {
53
+ let chainIdArray;
54
+ if (!!chainId) {
55
+ chainIdArray = [chainId];
92
56
  }
93
- const result = await batchMulticallCallWithRetry(chainId, { calls });
94
- const res = {};
95
- for (const [index, pool] of poolData.entries()) {
96
- let symbolCurrency0 = "";
97
- let decimalsCurrency0 = 0;
98
- let symbolCurrency1 = "";
99
- let decimalsCurrency1 = 0;
100
- try {
101
- symbolCurrency0 = ERC20Interface.decodeFunctionResult("symbol", result[index * 4].returnData)[0];
102
- }
103
- catch { }
104
- try {
105
- decimalsCurrency0 = ERC20Interface.decodeFunctionResult("decimals", result[index * 4 + 1].returnData)[0];
106
- }
107
- catch { }
108
- try {
109
- symbolCurrency1 = ERC20Interface.decodeFunctionResult("symbol", result[index * 4 + 2].returnData)[0];
110
- }
111
- catch { }
112
- try {
113
- decimalsCurrency1 = ERC20Interface.decodeFunctionResult("decimals", result[index * 4 + 3].returnData)[0];
114
- }
115
- catch { }
116
- res[pool.poolId] = { ...pool, symbolCurrency0, decimalsCurrency0, symbolCurrency1, decimalsCurrency1 };
57
+ else {
58
+ chainIdArray = UniV4ChainIdArray;
117
59
  }
118
- return res;
119
- }
120
- static async getPools() {
121
- const UNIV4_CHAINIDS = Object.keys(UniswapV4Addresses).map((x) => Number(x));
122
60
  const pools = {};
123
- // 0_ Fetch all euler vaults from database
124
- const storedPools = await UniswapRepository.getStoredPools();
125
- const res = await Promise.all(UNIV4_CHAINIDS.map(async (chainId) => {
61
+ // 0_ Fetch all univ4 pools from API database
62
+ const storedPools = await UniswapRepository.getStoredUniswapV4Pools(chainId);
63
+ const res = await Promise.all(chainIdArray.map(async (chainId) => {
126
64
  chainId = chainId;
127
65
  const perChainIdRes = {};
128
66
  const poolManagerAddress = UniswapV4Addresses[chainId]?.PoolManager ?? NULL_ADDRESS;
129
67
  const jsonRPCprovider = providers[chainId];
130
68
  try {
131
- // 1_ Get latest euler vaults from chain
69
+ // 1_ Get latest uniswapV4 pools for `chainId`
132
70
  const storedPoolsPerChain = storedPools.filter(pool => pool.chainId === chainId);
133
71
  log.info(`found ${storedPoolsPerChain.length} already stored pools on ${NETWORK_LABELS[chainId]}`);
134
72
  let fromBlock;
@@ -140,12 +78,10 @@ export class UniswapService {
140
78
  }
141
79
  const toBlock = await jsonRPCprovider.getBlockNumber();
142
80
  const logs = await safeFetchLogs(chainId, // TODO: rm type enforcing
143
- [UniswapV4PoolManagerInterface.getEventTopic("Initialize")], [poolManagerAddress], fromBlock, toBlock
144
- // fromBlock + 10_000
145
- );
81
+ [UniswapV4PoolManagerInterface.getEventTopic("Initialize")], [poolManagerAddress], fromBlock, toBlock);
146
82
  const decodedPools = await Promise.all(logs.map(async (log) => {
147
83
  const [id, currency0, currency1, fee, tickSpacing, hooks] = UniswapV4PoolManagerInterface.decodeEventLog("Initialize", log.data, log.topics);
148
- // Respect typing
84
+ // Match typing
149
85
  return {
150
86
  poolId: id,
151
87
  chainId: chainId,
@@ -247,13 +183,13 @@ export class UniswapService {
247
183
  }
248
184
  return perChainIdRes;
249
185
  }));
250
- UNIV4_CHAINIDS.forEach((chainId, i) => {
186
+ chainIdArray.forEach((chainId, i) => {
251
187
  if (!!res[i])
252
188
  pools[chainId] = res[i];
253
189
  });
254
190
  // Update the API database
255
191
  const tableData = Object.values(pools).flatMap(pools => Object.values(pools));
256
- for (const chainId of UNIV4_CHAINIDS) {
192
+ for (const chainId of chainIdArray) {
257
193
  if (tableData.filter(p => p.chainId === chainId).length > 0) {
258
194
  try {
259
195
  await UniswapRepository.createMany(tableData
@@ -288,4 +224,8 @@ export class UniswapService {
288
224
  log.info("👋 exiting getUniswapV4Pools");
289
225
  return pools;
290
226
  }
227
+ /** @deprecated */
228
+ static async getUniswapV4PoolsForChain(chainId) {
229
+ return await UniswapService.getUniswapV4Pools(chainId);
230
+ }
291
231
  }
@@ -1,16 +1,16 @@
1
1
  import { Redis } from "@/cache";
2
- import { UniV4ChainIdArray, getUniswapV4Pools } from "@/engine/dynamicData/utils/getUniswapV4Pools";
3
2
  import { ChainUniqueDto } from "@/modules/v4/chain/chain.model";
4
- import { Bytes32Dto } from "@/modules/v4/uniswap/uniswap.model";
3
+ import { Bytes32Dto, UniV4ChainIdArray } from "@/modules/v4/uniswap/uniswap.model";
4
+ import { UniswapService } from "@/modules/v4/uniswap/uniswap.service";
5
5
  import { UnsupportedNetwork } from "@/utils/error";
6
6
  export default (app) => app.group("/uniswapv4", router => router
7
7
  .get("/", async () => {
8
- return await Redis.getOrSet("UniswapV4Pools", getUniswapV4Pools);
8
+ return await Redis.getOrSet("UniswapV4Pools", UniswapService.getUniswapV4Pools);
9
9
  }, {
10
10
  tags: ["uniswapv4"],
11
11
  })
12
12
  .get("/:chainId", async ({ params }) => {
13
- return (await Redis.getOrSet("UniswapV4Pools", getUniswapV4Pools, params.chainId))[params.chainId];
13
+ return (await Redis.getOrSet("UniswapV4Pools", UniswapService.getUniswapV4Pools, params.chainId))[params.chainId];
14
14
  }, {
15
15
  params: ChainUniqueDto,
16
16
  beforeHandle: ({ params }) => {
@@ -20,7 +20,7 @@ export default (app) => app.group("/uniswapv4", router => router
20
20
  tags: ["uniswapv4"],
21
21
  })
22
22
  .get("/pool/:poolId", async ({ params }) => {
23
- return Object.values((await Redis.getOrSet("UniswapV4Pools", getUniswapV4Pools)))
23
+ return Object.values((await Redis.getOrSet("UniswapV4Pools", UniswapService.getUniswapV4Pools)))
24
24
  .flatMap(x => (x ? Object.values(x) : []))
25
25
  .filter(p => p.poolId === params.poolId);
26
26
  }, {