@merkl/api 0.15.43 → 0.15.44
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/constants.d.ts
CHANGED
@@ -31,7 +31,7 @@ export declare const DOPEX_OPTION_MARKET: {
|
|
31
31
|
[market: string]: string;
|
32
32
|
};
|
33
33
|
export declare const constantChain: {
|
34
|
-
[
|
34
|
+
[x: number]: {
|
35
35
|
apw: string;
|
36
36
|
convexEndpoint: string;
|
37
37
|
crv: string;
|
@@ -55,8 +55,28 @@ export declare const constantChain: {
|
|
55
55
|
usdc: string;
|
56
56
|
weth: string;
|
57
57
|
wstETH: string;
|
58
|
-
|
59
|
-
|
58
|
+
arb?: undefined;
|
59
|
+
chr?: undefined;
|
60
|
+
convexProxy?: undefined;
|
61
|
+
crv2Pool?: undefined;
|
62
|
+
jeur?: undefined;
|
63
|
+
ram?: undefined;
|
64
|
+
sliz?: undefined;
|
65
|
+
mai?: undefined;
|
66
|
+
op?: undefined;
|
67
|
+
usdce?: undefined;
|
68
|
+
velo?: undefined;
|
69
|
+
veloV2?: undefined;
|
70
|
+
aero?: undefined;
|
71
|
+
am3CRV?: undefined;
|
72
|
+
amDAI?: undefined;
|
73
|
+
amUSDC?: undefined;
|
74
|
+
amUSDT?: undefined;
|
75
|
+
jrt?: undefined;
|
76
|
+
oretro?: undefined;
|
77
|
+
glcr?: undefined;
|
78
|
+
cake?: undefined;
|
79
|
+
} | {
|
60
80
|
arb: string;
|
61
81
|
chr: string;
|
62
82
|
convexProxy: string;
|
@@ -70,8 +90,38 @@ export declare const constantChain: {
|
|
70
90
|
sliz: string;
|
71
91
|
stakeEndpoint: string;
|
72
92
|
usdc: string;
|
73
|
-
|
74
|
-
|
93
|
+
apw?: undefined;
|
94
|
+
convexEndpoint?: undefined;
|
95
|
+
crv3?: undefined;
|
96
|
+
crvANGLESDANGLE?: undefined;
|
97
|
+
crvEURAEUROC?: undefined;
|
98
|
+
crvEURAEURe?: undefined;
|
99
|
+
crvEuropool?: undefined;
|
100
|
+
crvFRAX?: undefined;
|
101
|
+
crvFRAXEURA?: undefined;
|
102
|
+
crvLUSD3CRV?: undefined;
|
103
|
+
dai?: undefined;
|
104
|
+
fxs?: undefined;
|
105
|
+
morpho?: undefined;
|
106
|
+
rKP3R?: undefined;
|
107
|
+
sushi?: undefined;
|
108
|
+
weth?: undefined;
|
109
|
+
wstETH?: undefined;
|
110
|
+
mai?: undefined;
|
111
|
+
op?: undefined;
|
112
|
+
usdce?: undefined;
|
113
|
+
velo?: undefined;
|
114
|
+
veloV2?: undefined;
|
115
|
+
aero?: undefined;
|
116
|
+
am3CRV?: undefined;
|
117
|
+
amDAI?: undefined;
|
118
|
+
amUSDC?: undefined;
|
119
|
+
amUSDT?: undefined;
|
120
|
+
jrt?: undefined;
|
121
|
+
oretro?: undefined;
|
122
|
+
glcr?: undefined;
|
123
|
+
cake?: undefined;
|
124
|
+
} | {
|
75
125
|
jeur: string;
|
76
126
|
mai: string;
|
77
127
|
op: string;
|
@@ -79,12 +129,89 @@ export declare const constantChain: {
|
|
79
129
|
usdce: string;
|
80
130
|
velo: string;
|
81
131
|
veloV2: string;
|
82
|
-
|
83
|
-
|
132
|
+
apw?: undefined;
|
133
|
+
convexEndpoint?: undefined;
|
134
|
+
crv?: undefined;
|
135
|
+
crv3?: undefined;
|
136
|
+
crvANGLESDANGLE?: undefined;
|
137
|
+
crvEURAEUROC?: undefined;
|
138
|
+
crvEURAEURe?: undefined;
|
139
|
+
crvEuropool?: undefined;
|
140
|
+
crvFRAX?: undefined;
|
141
|
+
crvFRAXEURA?: undefined;
|
142
|
+
crvLUSD3CRV?: undefined;
|
143
|
+
cvx?: undefined;
|
144
|
+
dai?: undefined;
|
145
|
+
frax?: undefined;
|
146
|
+
fxs?: undefined;
|
147
|
+
morpho?: undefined;
|
148
|
+
rKP3R?: undefined;
|
149
|
+
sdt?: undefined;
|
150
|
+
stakeEndpoint?: undefined;
|
151
|
+
sushi?: undefined;
|
152
|
+
weth?: undefined;
|
153
|
+
wstETH?: undefined;
|
154
|
+
arb?: undefined;
|
155
|
+
chr?: undefined;
|
156
|
+
convexProxy?: undefined;
|
157
|
+
crv2Pool?: undefined;
|
158
|
+
ram?: undefined;
|
159
|
+
sliz?: undefined;
|
160
|
+
aero?: undefined;
|
161
|
+
am3CRV?: undefined;
|
162
|
+
amDAI?: undefined;
|
163
|
+
amUSDC?: undefined;
|
164
|
+
amUSDT?: undefined;
|
165
|
+
jrt?: undefined;
|
166
|
+
oretro?: undefined;
|
167
|
+
glcr?: undefined;
|
168
|
+
cake?: undefined;
|
169
|
+
} | {
|
84
170
|
aero: string;
|
85
171
|
usdc: string;
|
86
|
-
|
87
|
-
|
172
|
+
apw?: undefined;
|
173
|
+
convexEndpoint?: undefined;
|
174
|
+
crv?: undefined;
|
175
|
+
crv3?: undefined;
|
176
|
+
crvANGLESDANGLE?: undefined;
|
177
|
+
crvEURAEUROC?: undefined;
|
178
|
+
crvEURAEURe?: undefined;
|
179
|
+
crvEuropool?: undefined;
|
180
|
+
crvFRAX?: undefined;
|
181
|
+
crvFRAXEURA?: undefined;
|
182
|
+
crvLUSD3CRV?: undefined;
|
183
|
+
cvx?: undefined;
|
184
|
+
dai?: undefined;
|
185
|
+
frax?: undefined;
|
186
|
+
fxs?: undefined;
|
187
|
+
morpho?: undefined;
|
188
|
+
rKP3R?: undefined;
|
189
|
+
sdt?: undefined;
|
190
|
+
stakeEndpoint?: undefined;
|
191
|
+
sushi?: undefined;
|
192
|
+
weth?: undefined;
|
193
|
+
wstETH?: undefined;
|
194
|
+
arb?: undefined;
|
195
|
+
chr?: undefined;
|
196
|
+
convexProxy?: undefined;
|
197
|
+
crv2Pool?: undefined;
|
198
|
+
jeur?: undefined;
|
199
|
+
ram?: undefined;
|
200
|
+
sliz?: undefined;
|
201
|
+
mai?: undefined;
|
202
|
+
op?: undefined;
|
203
|
+
usdce?: undefined;
|
204
|
+
velo?: undefined;
|
205
|
+
veloV2?: undefined;
|
206
|
+
am3CRV?: undefined;
|
207
|
+
amDAI?: undefined;
|
208
|
+
amUSDC?: undefined;
|
209
|
+
amUSDT?: undefined;
|
210
|
+
jrt?: undefined;
|
211
|
+
oretro?: undefined;
|
212
|
+
glcr?: undefined;
|
213
|
+
cake?: undefined;
|
214
|
+
} | {
|
88
215
|
am3CRV: string;
|
89
216
|
amDAI: string;
|
90
217
|
amUSDC: string;
|
@@ -93,13 +220,132 @@ export declare const constantChain: {
|
|
93
220
|
jrt: string;
|
94
221
|
oretro: string;
|
95
222
|
usdc: string;
|
96
|
-
|
97
|
-
|
223
|
+
apw?: undefined;
|
224
|
+
convexEndpoint?: undefined;
|
225
|
+
crv?: undefined;
|
226
|
+
crv3?: undefined;
|
227
|
+
crvANGLESDANGLE?: undefined;
|
228
|
+
crvEURAEUROC?: undefined;
|
229
|
+
crvEURAEURe?: undefined;
|
230
|
+
crvEuropool?: undefined;
|
231
|
+
crvFRAX?: undefined;
|
232
|
+
crvFRAXEURA?: undefined;
|
233
|
+
crvLUSD3CRV?: undefined;
|
234
|
+
cvx?: undefined;
|
235
|
+
dai?: undefined;
|
236
|
+
frax?: undefined;
|
237
|
+
fxs?: undefined;
|
238
|
+
morpho?: undefined;
|
239
|
+
rKP3R?: undefined;
|
240
|
+
sdt?: undefined;
|
241
|
+
stakeEndpoint?: undefined;
|
242
|
+
sushi?: undefined;
|
243
|
+
weth?: undefined;
|
244
|
+
wstETH?: undefined;
|
245
|
+
arb?: undefined;
|
246
|
+
chr?: undefined;
|
247
|
+
convexProxy?: undefined;
|
248
|
+
crv2Pool?: undefined;
|
249
|
+
ram?: undefined;
|
250
|
+
sliz?: undefined;
|
251
|
+
mai?: undefined;
|
252
|
+
op?: undefined;
|
253
|
+
usdce?: undefined;
|
254
|
+
velo?: undefined;
|
255
|
+
veloV2?: undefined;
|
256
|
+
aero?: undefined;
|
257
|
+
glcr?: undefined;
|
258
|
+
cake?: undefined;
|
259
|
+
} | {
|
98
260
|
glcr: string;
|
99
261
|
usdc: string;
|
100
|
-
|
101
|
-
|
262
|
+
apw?: undefined;
|
263
|
+
convexEndpoint?: undefined;
|
264
|
+
crv?: undefined;
|
265
|
+
crv3?: undefined;
|
266
|
+
crvANGLESDANGLE?: undefined;
|
267
|
+
crvEURAEUROC?: undefined;
|
268
|
+
crvEURAEURe?: undefined;
|
269
|
+
crvEuropool?: undefined;
|
270
|
+
crvFRAX?: undefined;
|
271
|
+
crvFRAXEURA?: undefined;
|
272
|
+
crvLUSD3CRV?: undefined;
|
273
|
+
cvx?: undefined;
|
274
|
+
dai?: undefined;
|
275
|
+
frax?: undefined;
|
276
|
+
fxs?: undefined;
|
277
|
+
morpho?: undefined;
|
278
|
+
rKP3R?: undefined;
|
279
|
+
sdt?: undefined;
|
280
|
+
stakeEndpoint?: undefined;
|
281
|
+
sushi?: undefined;
|
282
|
+
weth?: undefined;
|
283
|
+
wstETH?: undefined;
|
284
|
+
arb?: undefined;
|
285
|
+
chr?: undefined;
|
286
|
+
convexProxy?: undefined;
|
287
|
+
crv2Pool?: undefined;
|
288
|
+
jeur?: undefined;
|
289
|
+
ram?: undefined;
|
290
|
+
sliz?: undefined;
|
291
|
+
mai?: undefined;
|
292
|
+
op?: undefined;
|
293
|
+
usdce?: undefined;
|
294
|
+
velo?: undefined;
|
295
|
+
veloV2?: undefined;
|
296
|
+
aero?: undefined;
|
297
|
+
am3CRV?: undefined;
|
298
|
+
amDAI?: undefined;
|
299
|
+
amUSDC?: undefined;
|
300
|
+
amUSDT?: undefined;
|
301
|
+
jrt?: undefined;
|
302
|
+
oretro?: undefined;
|
303
|
+
cake?: undefined;
|
304
|
+
} | {
|
102
305
|
cake: string;
|
306
|
+
apw?: undefined;
|
307
|
+
convexEndpoint?: undefined;
|
308
|
+
crv?: undefined;
|
309
|
+
crv3?: undefined;
|
310
|
+
crvANGLESDANGLE?: undefined;
|
311
|
+
crvEURAEUROC?: undefined;
|
312
|
+
crvEURAEURe?: undefined;
|
313
|
+
crvEuropool?: undefined;
|
314
|
+
crvFRAX?: undefined;
|
315
|
+
crvFRAXEURA?: undefined;
|
316
|
+
crvLUSD3CRV?: undefined;
|
317
|
+
cvx?: undefined;
|
318
|
+
dai?: undefined;
|
319
|
+
frax?: undefined;
|
320
|
+
fxs?: undefined;
|
321
|
+
morpho?: undefined;
|
322
|
+
rKP3R?: undefined;
|
323
|
+
sdt?: undefined;
|
324
|
+
stakeEndpoint?: undefined;
|
325
|
+
sushi?: undefined;
|
326
|
+
usdc?: undefined;
|
327
|
+
weth?: undefined;
|
328
|
+
wstETH?: undefined;
|
329
|
+
arb?: undefined;
|
330
|
+
chr?: undefined;
|
331
|
+
convexProxy?: undefined;
|
332
|
+
crv2Pool?: undefined;
|
333
|
+
jeur?: undefined;
|
334
|
+
ram?: undefined;
|
335
|
+
sliz?: undefined;
|
336
|
+
mai?: undefined;
|
337
|
+
op?: undefined;
|
338
|
+
usdce?: undefined;
|
339
|
+
velo?: undefined;
|
340
|
+
veloV2?: undefined;
|
341
|
+
aero?: undefined;
|
342
|
+
am3CRV?: undefined;
|
343
|
+
amDAI?: undefined;
|
344
|
+
amUSDC?: undefined;
|
345
|
+
amUSDT?: undefined;
|
346
|
+
jrt?: undefined;
|
347
|
+
oretro?: undefined;
|
348
|
+
glcr?: undefined;
|
103
349
|
};
|
104
350
|
};
|
105
351
|
export declare const MAVERICK_ZKSYNC_BP_LENS_ADDRESS = "0xd32CE31CaC98CAC0631764B8286358c0606D87F9";
|
@@ -1160,7 +1160,7 @@ export const extractOpportunities = {
|
|
1160
1160
|
const opportunity = {
|
1161
1161
|
id: `${Campaign.UNISWAP_V4}_${mainParameter}`,
|
1162
1162
|
platform,
|
1163
|
-
name: [platform, pair, params.lpFee && `${params.lpFee} %`].join(" "),
|
1163
|
+
name: [platform, pair, params.lpFee && `${params.lpFee / 10_000} %`].join(" "),
|
1164
1164
|
chainId: computeChainId ?? chainId,
|
1165
1165
|
distributionChainId: chainId,
|
1166
1166
|
action: "pool",
|
@@ -1,8 +1,47 @@
|
|
1
|
-
import {
|
1
|
+
import { BucketService } from "../../../modules/v4/bucket/bucket.service";
|
2
|
+
import { engineDbClient } from "../../../utils/prisma";
|
3
|
+
import { BN2Number, ChainInteractionService, EAprBreakdownType, NETWORK_LABELS, UniswapV4Addresses, UniswapV4StateViewInterface, getSqrtRatioAtTick, shortenAddress, } from "@sdk";
|
2
4
|
import moment from "moment";
|
3
5
|
import { log } from "../../../utils/logger";
|
4
6
|
import { Pricer } from "../../../utils/pricer";
|
7
|
+
// Constants
|
5
8
|
const CALLS_LENGTH = 2;
|
9
|
+
/**
|
10
|
+
* Compute TVL
|
11
|
+
* @dev important: using the most recent state save with current prices
|
12
|
+
* it's only an estimate
|
13
|
+
*/
|
14
|
+
async function computeUniV4PoolTVLFromMostRecentStateSave(chainId, poolID, priceCurrency0, priceCurrency1, decimalsCurrency0, decimalsCurrency1) {
|
15
|
+
const currentBlock = await ChainInteractionService(chainId).getBlockNumber();
|
16
|
+
const mostRecentStateSave = await engineDbClient.stateSave.findFirst({
|
17
|
+
where: {
|
18
|
+
id: `UniswapV4_${chainId}_${poolID}`,
|
19
|
+
blockNumber: {
|
20
|
+
lte: currentBlock,
|
21
|
+
},
|
22
|
+
},
|
23
|
+
orderBy: {
|
24
|
+
blockNumber: "desc",
|
25
|
+
},
|
26
|
+
});
|
27
|
+
const stateSave = mostRecentStateSave.state;
|
28
|
+
const blockNumber = mostRecentStateSave?.blockNumber;
|
29
|
+
const states = stateSave.states;
|
30
|
+
// const globalState = stateSave.globalState as { tick: number; liquidity: string };
|
31
|
+
const { fileName, bucketName } = states;
|
32
|
+
// Bucket service
|
33
|
+
const bucket = new BucketService(bucketName, "merkl-production");
|
34
|
+
const storedStates = JSON.parse(await bucket.pull(fileName));
|
35
|
+
let tvl = 0;
|
36
|
+
let amount0 = 0;
|
37
|
+
let amount1 = 0;
|
38
|
+
for (const [_, { value, params }] of Object.entries(storedStates)) {
|
39
|
+
amount0 += BN2Number(value.amount0, decimalsCurrency0);
|
40
|
+
amount1 += BN2Number(value.amount1, decimalsCurrency1);
|
41
|
+
}
|
42
|
+
tvl = amount0 * (priceCurrency0 ?? 0) + amount1 * (priceCurrency1 ?? 0);
|
43
|
+
return { tvl, amount0, amount1, blockNumber: blockNumber };
|
44
|
+
}
|
6
45
|
export async function UniswapV4DynamicData(chainId, campaigns) {
|
7
46
|
const dynamicData = [];
|
8
47
|
const pricer = await Pricer.load();
|
@@ -28,18 +67,7 @@ export async function UniswapV4DynamicData(chainId, campaigns) {
|
|
28
67
|
allowFailure: true,
|
29
68
|
callData: UniswapV4StateViewInterface.encodeFunctionData("getSlot0", [pool.poolId]),
|
30
69
|
target: UniswapV4Addresses[chainId].StateView,
|
31
|
-
}
|
32
|
-
// {
|
33
|
-
// allowFailure: true,
|
34
|
-
// callData: ERC20Interface.encodeFunctionData("balanceOf", [pool.address]),
|
35
|
-
// target: d.campaignParameters.token0,
|
36
|
-
// },
|
37
|
-
// {
|
38
|
-
// allowFailure: true,
|
39
|
-
// callData: ERC20Interface.encodeFunctionData("balanceOf", [pool.address]),
|
40
|
-
// target: d.campaignParameters.token1,
|
41
|
-
// }
|
42
|
-
);
|
70
|
+
});
|
43
71
|
}
|
44
72
|
return {
|
45
73
|
cached: false,
|
@@ -54,43 +82,38 @@ export async function UniswapV4DynamicData(chainId, campaigns) {
|
|
54
82
|
let poolTotalLiquidity;
|
55
83
|
let sqrtPrice;
|
56
84
|
let tick;
|
57
|
-
|
58
|
-
|
85
|
+
let poolBalanceToken0 = 0;
|
86
|
+
let poolBalanceToken1 = 0;
|
59
87
|
const campaignsForPool = campaigns?.filter(campaign => campaign.mainParameter.toLowerCase() === pool.mainParameter.toLowerCase());
|
60
|
-
// const decimalsToken0 = d.campaignParameters.decimalsCurrency0;
|
61
|
-
// const decimalsToken1 = d.campaignParameters.decimalsCurrency1;
|
62
|
-
const symbolToken0 = campaignsForPool[0].campaignParameters.symbolCurrency0;
|
63
|
-
const symbolToken1 = campaignsForPool[0].campaignParameters.symbolCurrency1;
|
64
88
|
const prevI = i;
|
65
89
|
try {
|
66
90
|
poolTotalLiquidity = UniswapV4StateViewInterface.decodeFunctionResult("getLiquidity", result[i++])[0].toString();
|
67
91
|
const poolData = UniswapV4StateViewInterface.decodeFunctionResult("getSlot0", result[i++]);
|
68
92
|
tick = poolData.tick;
|
69
93
|
sqrtPrice = getSqrtRatioAtTick(tick).toString();
|
70
|
-
// poolBalanceToken0 = BN2Number(
|
71
|
-
// ERC20Interface.decodeFunctionResult("balanceOf", result[i++])[0],
|
72
|
-
// decimalsToken0
|
73
|
-
// );
|
74
|
-
// poolBalanceToken1 = BN2Number(
|
75
|
-
// ERC20Interface.decodeFunctionResult("balanceOf", result[i++])[0],
|
76
|
-
// decimalsToken1
|
77
|
-
// );
|
78
94
|
}
|
79
95
|
catch {
|
80
96
|
log.warn(`merklDynamic data - failed to decode state of pool ${pool.poolId} on ${NETWORK_LABELS[chainId]}`);
|
81
97
|
i = prevI + CALLS_LENGTH;
|
82
98
|
continue;
|
83
99
|
}
|
100
|
+
const decimalsCurrency0 = campaignsForPool[0].campaignParameters.decimalsCurrency0;
|
101
|
+
const decimalsCurrency1 = campaignsForPool[0].campaignParameters.decimalsCurrency1;
|
102
|
+
const symbolCurrency0 = campaignsForPool[0].campaignParameters.symbolCurrency0;
|
103
|
+
const symbolCurrency1 = campaignsForPool[0].campaignParameters.symbolCurrency1;
|
84
104
|
const priceToken0 = (await pricer.get({
|
85
105
|
address: campaignsForPool[0].campaignParameters.currency0,
|
86
106
|
chainId: chainId,
|
87
|
-
symbol:
|
107
|
+
symbol: symbolCurrency0,
|
88
108
|
}));
|
89
109
|
const priceToken1 = (await pricer.get({
|
90
110
|
address: campaignsForPool[0].campaignParameters.currency1,
|
91
111
|
chainId: chainId,
|
92
|
-
symbol:
|
112
|
+
symbol: symbolCurrency1,
|
93
113
|
}));
|
114
|
+
const { tvl, amount0, amount1, blockNumber } = await computeUniV4PoolTVLFromMostRecentStateSave(chainId, pool.poolId, priceToken0, priceToken1, decimalsCurrency0, decimalsCurrency1);
|
115
|
+
poolBalanceToken0 += amount0;
|
116
|
+
poolBalanceToken1 += amount1;
|
94
117
|
/** Iterate over distributions to compute APRs */
|
95
118
|
for (const campaign of campaignsForPool) {
|
96
119
|
const c = campaign;
|
@@ -135,8 +158,8 @@ export async function UniswapV4DynamicData(chainId, campaigns) {
|
|
135
158
|
/**
|
136
159
|
* General APR (@notice potentially with a boost)
|
137
160
|
*/
|
138
|
-
const poolBalanceToken0WithoutBlacklist =
|
139
|
-
const poolBalanceToken1WithoutBlacklist =
|
161
|
+
const poolBalanceToken0WithoutBlacklist = poolBalanceToken0;
|
162
|
+
const poolBalanceToken1WithoutBlacklist = poolBalanceToken1;
|
140
163
|
// const poolLiquidityWithoutBlacklist = poolTotalLiquidity - (blacklistedLiquidity ?? 0);
|
141
164
|
const tvl = poolBalanceToken0WithoutBlacklist * priceToken0 + poolBalanceToken1WithoutBlacklist * priceToken1;
|
142
165
|
distributionMeanAPR = (yearlyToken0Rewards + yearlyToken1Rewards + yearlyFeeRewards) / tvl;
|