@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.
- package/dist/src/backgroundJobs/index.js +5 -3
- package/dist/src/eden/index.d.ts +280 -91
- package/dist/src/engine/dynamicData/factory.js +6 -0
- package/dist/src/engine/dynamicData/implementations/Erc20.d.ts +2 -2
- package/dist/src/engine/dynamicData/implementations/Erc20.js +16 -2
- package/dist/src/engine/dynamicData/implementations/UniswapV4.js +1 -1
- package/dist/src/engine/opportunityMetadata/factory.js +6 -0
- package/dist/src/engine/opportunityMetadata/implementations/Clamm.js +8 -1
- package/dist/src/index.d.ts +72 -15
- package/dist/src/jobs/update-uniswap-v4-pools.js +3 -2
- package/dist/src/modules/v4/accounting/accounting.repository.js +72 -18
- package/dist/src/modules/v4/router.d.ts +72 -15
- package/dist/src/modules/v4/uniswap/uniswap.controller.d.ts +72 -15
- package/dist/src/modules/v4/uniswap/uniswap.controller.js +49 -6
- package/dist/src/modules/v4/uniswap/uniswap.model.d.ts +35 -16
- package/dist/src/modules/v4/uniswap/uniswap.model.js +22 -8
- package/dist/src/modules/v4/uniswap/uniswap.repository.d.ts +2 -2
- package/dist/src/modules/v4/uniswap/uniswap.repository.js +2 -2
- package/dist/src/modules/v4/uniswap/uniswap.service.d.ts +4 -19
- package/dist/src/modules/v4/uniswap/uniswap.service.js +20 -80
- package/dist/src/routes/v3/uniswapv4.js +5 -5
- package/dist/tsconfig.package.tsbuildinfo +1 -1
- package/package.json +14 -14
- package/dist/src/engine/dynamicData/utils/getUniswapV4Pools.d.ts +0 -10
- package/dist/src/engine/dynamicData/utils/getUniswapV4Pools.js +0 -188
package/package.json
CHANGED
@@ -7,42 +7,42 @@
|
|
7
7
|
"dist"
|
8
8
|
],
|
9
9
|
"scripts": {
|
10
|
+
"build:ci": "bun tsc -b",
|
11
|
+
"build:local": "bun tsc -b",
|
10
12
|
"cmd": "bun run scripts/cmd.ts",
|
11
13
|
"container": "chmod +x scripts/run.sh && FORCE_COLOR=true ./scripts/run.sh bun run ./scripts/config.ts",
|
12
14
|
"db:generate": "bunx prisma generate --schema database/api/schema.prisma && bunx prisma generate --schema database/engine/schema.prisma",
|
15
|
+
"db:migrate:create": "bunx prisma migrate dev --create-only --schema database/api/schema.prisma",
|
13
16
|
"db:migrate:deploy": "bunx prisma migrate deploy --schema database/api/schema.prisma",
|
14
17
|
"db:migrate:dev": "bunx prisma migrate dev --schema database/api/schema.prisma",
|
15
|
-
"db:migrate:create": "bunx prisma migrate dev --create-only --schema database/api/schema.prisma",
|
16
18
|
"db:migrate:reset": "bunx prisma migrate reset --schema database/api/schema.prisma",
|
17
19
|
"db:studio:api": "bunx prisma studio --schema database/api/schema.prisma",
|
18
20
|
"db:studio:engine": "bunx prisma studio --schema database/engine/schema.prisma",
|
19
|
-
"build:ci": "bun tsc -b",
|
20
|
-
"build:local": "bun tsc -b",
|
21
21
|
"lint": "bun biome check --diagnostic-level error --write ./src && bun biome check --diagnostic-level error --write ./tests",
|
22
22
|
"lint:ci": "bun biome check --diagnostic-level error ./src",
|
23
23
|
"lint:test": "bun biome check --write ./tests",
|
24
24
|
"pack": "chmod +x scripts/pack.sh && ./scripts/pack.sh",
|
25
|
+
"postpublish": "bun run use:gitReadme",
|
26
|
+
"prepublishOnly": "bun run use:packageReadme",
|
25
27
|
"pull-db": "prisma db pull && prisma generate",
|
26
28
|
"pull-db:local": "DATABASE_URL=postgresql://postgres:postgres@0.0.0.0:5432/merkl-calc prisma db pull && prisma generate",
|
29
|
+
"set:dungeon-keeper": "bun run src/jobs/set-dungeon-keeper.ts",
|
27
30
|
"setup": "code --install-extension .vscode/extensions/merkl:helpers-0.0.1.vsix",
|
28
31
|
"sql": "lsof -i :1234 && lsof -i :2345",
|
32
|
+
"start:etl:pendings": "bun run src/jobs/pendings.ts",
|
33
|
+
"start:etl:reward-breakdowns": "bun run src/jobs/reward-breakdowns.ts",
|
34
|
+
"start:etl:rewards": "bun run src/jobs/rewards.ts",
|
29
35
|
"start:local": "bun scripts/start.ts",
|
30
36
|
"sync": "bun install && git submodule update --init --recursive && git submodule foreach 'bun install' && bun db:generate",
|
31
37
|
"test": "bun test",
|
32
|
-
"start:etl:rewards": "bun run src/jobs/rewards.ts",
|
33
|
-
"start:etl:reward-breakdowns": "bun run src/jobs/reward-breakdowns.ts",
|
34
|
-
"start:etl:pendings": "bun run src/jobs/pendings.ts",
|
35
|
-
"update:prices": "bun run src/jobs/prices.ts",
|
36
38
|
"update:dynamic-data": "bun run src/jobs/dynamic-data.ts",
|
37
|
-
"update:euler-vaults": "bun run src/jobs/update-euler-vaults",
|
38
39
|
"update:dynamic-data:v4": "bun run src/jobs/update-dynamic-data.ts",
|
39
|
-
"update:
|
40
|
+
"update:euler-vaults": "bun run src/jobs/update-euler-vaults",
|
41
|
+
"update:prices": "bun run src/jobs/prices.ts",
|
40
42
|
"update:rpc-calls-cache": "bun run src/jobs/update-rpc-calls-cache.ts",
|
41
|
-
"
|
42
|
-
"use:packageReadme": "mv 'README.md' 'git.README.md' && mv 'README.package.md' 'README.md'",
|
43
|
+
"update:uniswap-v4-pools": "bun run src/jobs/update-uniswap-v4-pools.ts",
|
43
44
|
"use:gitReadme": "mv 'README.md' 'README.package.md' && mv 'git.README.md' 'README.md'",
|
44
|
-
"
|
45
|
-
"postpublish": "bun run use:gitReadme"
|
45
|
+
"use:packageReadme": "mv 'README.md' 'git.README.md' && mv 'README.package.md' 'README.md'"
|
46
46
|
},
|
47
47
|
"dependencies": {
|
48
48
|
"@bogeychan/elysia-logger": "^0.1.8",
|
@@ -107,5 +107,5 @@
|
|
107
107
|
"access": "public",
|
108
108
|
"registry": "https://registry.npmjs.org/"
|
109
109
|
},
|
110
|
-
"version": "v0.20.
|
110
|
+
"version": "v0.20.54"
|
111
111
|
}
|
@@ -1,10 +0,0 @@
|
|
1
|
-
import { type MerklChainId, type UniswapV4PoolType } from "@sdk";
|
2
|
-
export declare const UniV4ChainIdArray: MerklChainId[];
|
3
|
-
type UniV4ChainId = (typeof UniV4ChainIdArray)[number];
|
4
|
-
export type UniswapV4PoolsReturnType = {
|
5
|
-
[chainId in MerklChainId]?: {
|
6
|
-
[poolId: string]: UniswapV4PoolType;
|
7
|
-
};
|
8
|
-
};
|
9
|
-
export declare function getUniswapV4Pools(chainId?: UniV4ChainId): Promise<UniswapV4PoolsReturnType>;
|
10
|
-
export {};
|
@@ -1,188 +0,0 @@
|
|
1
|
-
import { log } from "@/utils/logger";
|
2
|
-
import { providers } from "@/utils/providers";
|
3
|
-
import { apiDbClient } from "@db";
|
4
|
-
import { ChainInteractionService, ERC20Interface, NETWORK_LABELS, NULL_ADDRESS, UniswapV4Addresses, UniswapV4PoolManagerInterface, getContractCreationBlock, } from "@sdk";
|
5
|
-
import { safeFetchLogs } from "./fetchLogs";
|
6
|
-
import { LoggedEntityType } from "./getEulerV2Vaults";
|
7
|
-
export const UniV4ChainIdArray = Object.keys(UniswapV4Addresses).map((x) => Number(x));
|
8
|
-
export async function getUniswapV4Pools(chainId) {
|
9
|
-
let chainIdArray;
|
10
|
-
if (!!chainId) {
|
11
|
-
chainIdArray = [chainId];
|
12
|
-
}
|
13
|
-
else {
|
14
|
-
chainIdArray = UniV4ChainIdArray;
|
15
|
-
}
|
16
|
-
const pools = {};
|
17
|
-
// 0_ Fetch all euler vaults from database
|
18
|
-
const storedPools = await apiDbClient.logged.findMany({
|
19
|
-
where: { type: LoggedEntityType.UNISWAP_V4 },
|
20
|
-
});
|
21
|
-
const res = await Promise.all(chainIdArray.map(async (chainId) => {
|
22
|
-
chainId = chainId;
|
23
|
-
const perChainIdRes = {};
|
24
|
-
const poolManagerAddress = UniswapV4Addresses[chainId]?.PoolManager ?? NULL_ADDRESS;
|
25
|
-
const jsonRPCprovider = providers[chainId];
|
26
|
-
try {
|
27
|
-
// 1_ Get latest uniswapV4 pools for `chainId`
|
28
|
-
const storedPoolsPerChain = storedPools.filter(pool => pool.chainId === chainId);
|
29
|
-
log.info(`found ${storedPoolsPerChain.length} already stored pools on ${NETWORK_LABELS[chainId]}`);
|
30
|
-
let fromBlock;
|
31
|
-
if (storedPoolsPerChain.length > 0) {
|
32
|
-
fromBlock = Math.max(...storedPoolsPerChain.map(x => x.fetchAtBlock)) + 1;
|
33
|
-
}
|
34
|
-
else {
|
35
|
-
fromBlock = await getContractCreationBlock(poolManagerAddress, jsonRPCprovider);
|
36
|
-
}
|
37
|
-
const toBlock = await jsonRPCprovider.getBlockNumber();
|
38
|
-
const logs = await safeFetchLogs(chainId, // TODO: rm type enforcing
|
39
|
-
[UniswapV4PoolManagerInterface.getEventTopic("Initialize")], [poolManagerAddress], fromBlock, toBlock
|
40
|
-
// fromBlock + 10_000
|
41
|
-
);
|
42
|
-
const decodedPools = await Promise.all(logs.map(async (log) => {
|
43
|
-
const [id, currency0, currency1, fee, tickSpacing, hooks] = UniswapV4PoolManagerInterface.decodeEventLog("Initialize", log.data, log.topics);
|
44
|
-
// Respect typing
|
45
|
-
return {
|
46
|
-
poolId: id,
|
47
|
-
chainId: chainId,
|
48
|
-
currency0: currency0,
|
49
|
-
currency1: currency1,
|
50
|
-
tickSpacing: tickSpacing,
|
51
|
-
lpFee: fee,
|
52
|
-
hooks: hooks,
|
53
|
-
fetchedAtBlock: Number(log.blockNumber),
|
54
|
-
};
|
55
|
-
}));
|
56
|
-
log.local(`fetched ${decodedPools.length} pool(s) on ${NETWORK_LABELS[chainId] ?? "Sepolia"} between blocks ${fromBlock} and ${toBlock}`);
|
57
|
-
/** Extra calls batch to get the collateral addresses */
|
58
|
-
const resCurrencies = await ChainInteractionService(chainId).fetchState(decodedPools.flatMap(pool => {
|
59
|
-
return [
|
60
|
-
{
|
61
|
-
allowFailure: true,
|
62
|
-
callData: ERC20Interface.encodeFunctionData("symbol"),
|
63
|
-
target: pool.currency0,
|
64
|
-
},
|
65
|
-
{
|
66
|
-
allowFailure: true,
|
67
|
-
callData: ERC20Interface.encodeFunctionData("decimals"),
|
68
|
-
target: pool.currency0,
|
69
|
-
},
|
70
|
-
{
|
71
|
-
allowFailure: true,
|
72
|
-
callData: ERC20Interface.encodeFunctionData("symbol"),
|
73
|
-
target: pool.currency1,
|
74
|
-
},
|
75
|
-
{
|
76
|
-
allowFailure: true,
|
77
|
-
callData: ERC20Interface.encodeFunctionData("decimals"),
|
78
|
-
target: pool.currency1,
|
79
|
-
},
|
80
|
-
].filter(x => x.target !== NULL_ADDRESS);
|
81
|
-
}));
|
82
|
-
let index = 0;
|
83
|
-
for (const pool of decodedPools) {
|
84
|
-
let symbolCurrency0 = "UNKNOWN";
|
85
|
-
let decimalsCurrency0 = 18;
|
86
|
-
if (pool.currency0 !== NULL_ADDRESS) {
|
87
|
-
try {
|
88
|
-
symbolCurrency0 = ERC20Interface.decodeFunctionResult("symbol", resCurrencies[index].returnData)[0];
|
89
|
-
if (symbolCurrency0.includes("/") || symbolCurrency0.includes("\u0000")) {
|
90
|
-
symbolCurrency0 = "INVALID";
|
91
|
-
}
|
92
|
-
decimalsCurrency0 = ERC20Interface.decodeFunctionResult("decimals", resCurrencies[index + 1].returnData)[0];
|
93
|
-
}
|
94
|
-
catch {
|
95
|
-
log.error("getUniswapV4Pools", `issue when fetching symbol / decimals for currency0 ${pool.currency0} of pool ${pool.poolId} on ${NETWORK_LABELS[chainId]}`);
|
96
|
-
}
|
97
|
-
}
|
98
|
-
else {
|
99
|
-
symbolCurrency0 = "ETH";
|
100
|
-
decimalsCurrency0 = 18;
|
101
|
-
index -= 2;
|
102
|
-
}
|
103
|
-
let symbolCurrency1 = "UNKNOWN";
|
104
|
-
let decimalsCurrency1 = 18;
|
105
|
-
if (pool.currency1 !== NULL_ADDRESS) {
|
106
|
-
try {
|
107
|
-
symbolCurrency1 = ERC20Interface.decodeFunctionResult("symbol", resCurrencies[index + 2].returnData)[0];
|
108
|
-
if (symbolCurrency1.includes("/") || symbolCurrency1.includes("\u0000")) {
|
109
|
-
symbolCurrency1 = "INVALID";
|
110
|
-
}
|
111
|
-
decimalsCurrency1 = ERC20Interface.decodeFunctionResult("decimals", resCurrencies[index + 3].returnData)[0];
|
112
|
-
}
|
113
|
-
catch {
|
114
|
-
log.error("getUniswapV4Pools", `issue when fetching symbol / decimals for currency1 ${pool.currency1} of pool ${pool.poolId} on ${NETWORK_LABELS[chainId]}`);
|
115
|
-
}
|
116
|
-
}
|
117
|
-
else {
|
118
|
-
symbolCurrency1 = "ETH";
|
119
|
-
decimalsCurrency1 = 18;
|
120
|
-
index -= 2;
|
121
|
-
}
|
122
|
-
const id = pool.poolId;
|
123
|
-
perChainIdRes[id ?? "unknownKey"] = {
|
124
|
-
chainId: pool.chainId,
|
125
|
-
currency0: pool.currency0,
|
126
|
-
currency1: pool.currency1,
|
127
|
-
decimalsCurrency0,
|
128
|
-
decimalsCurrency1,
|
129
|
-
hooks: pool.hooks,
|
130
|
-
fetchedAtBlock: pool.fetchedAtBlock,
|
131
|
-
lpFee: pool.lpFee,
|
132
|
-
poolId: id,
|
133
|
-
poolKey: pool.poolKey,
|
134
|
-
symbolCurrency0,
|
135
|
-
symbolCurrency1,
|
136
|
-
tickSpacing: pool.tickSpacing,
|
137
|
-
};
|
138
|
-
index += 4;
|
139
|
-
}
|
140
|
-
}
|
141
|
-
catch (e) {
|
142
|
-
log.error(`issue when fetching UniswapV4 pools on ${NETWORK_LABELS[chainId]}`, e);
|
143
|
-
}
|
144
|
-
return perChainIdRes;
|
145
|
-
}));
|
146
|
-
chainIdArray.forEach((chainId, i) => {
|
147
|
-
if (!!res[i])
|
148
|
-
pools[chainId] = res[i];
|
149
|
-
});
|
150
|
-
// Update the API database
|
151
|
-
const tableData = Object.values(pools).flatMap(pools => Object.values(pools));
|
152
|
-
for (const chainId of chainIdArray) {
|
153
|
-
if (tableData.filter(p => p.chainId === chainId).length > 0) {
|
154
|
-
try {
|
155
|
-
await apiDbClient.logged.createMany({
|
156
|
-
data: tableData
|
157
|
-
.filter(point => point.chainId === chainId)
|
158
|
-
.map(pool => ({
|
159
|
-
fetchAtBlock: pool.fetchedAtBlock,
|
160
|
-
caughtFromAddress: UniswapV4Addresses[pool.chainId]?.PoolManager ?? NULL_ADDRESS,
|
161
|
-
chainId: pool.chainId,
|
162
|
-
entityData: pool,
|
163
|
-
id: Bun.hash(`${pool.poolId}-${pool.chainId}`).toString(),
|
164
|
-
type: LoggedEntityType.UNISWAP_V4,
|
165
|
-
})),
|
166
|
-
});
|
167
|
-
log.info(`✅ successfully saved vaults to API database ('Logged' table) on ${NETWORK_LABELS[chainId]}`);
|
168
|
-
}
|
169
|
-
catch (e) {
|
170
|
-
log.error("getUniswapV4Pools/LoggedTableUpdate", e);
|
171
|
-
throw new Error(`Error while saving UniV4 pools to API database ('Logged' table) on ${NETWORK_LABELS[chainId]}`);
|
172
|
-
}
|
173
|
-
}
|
174
|
-
}
|
175
|
-
log.info(`✅ successfully fetched ${tableData.length} new pool(s) on UniswapV4`);
|
176
|
-
// _ Merge previoulsy stored pools with newly fetched ones
|
177
|
-
// TODO optimize this part
|
178
|
-
if (storedPools.length > 0) {
|
179
|
-
for (const pool of storedPools) {
|
180
|
-
const chainId = pool.chainId;
|
181
|
-
if (!pools[chainId])
|
182
|
-
pools[chainId] = {};
|
183
|
-
pools[chainId][pool.entityData.poolId] = pool.entityData;
|
184
|
-
}
|
185
|
-
}
|
186
|
-
log.info("👋 exiting getUniswapV4Pools");
|
187
|
-
return pools;
|
188
|
-
}
|