@merkl/api 0.15.45 → 0.15.47
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 +13 -259
- package/dist/src/eden/index.d.ts +0 -115
- package/dist/src/index.d.ts +0 -27
- package/dist/src/jobs/etl/pendings.js +52 -44
- package/dist/src/modules/v4/programPayload/programPayload.repository.d.ts +14 -2
- package/dist/src/modules/v4/programPayload/programPayload.repository.js +163 -0
- package/dist/src/modules/v4/reward/reward.controller.d.ts +0 -27
- package/dist/src/modules/v4/reward/reward.controller.js +1 -8
- package/dist/src/modules/v4/router.d.ts +0 -27
- package/dist/tsconfig.package.tsbuildinfo +1 -1
- package/package.json +1 -1
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
|
+
[ChainId.MAINNET]: {
|
35
35
|
apw: string;
|
36
36
|
convexEndpoint: string;
|
37
37
|
crv: string;
|
@@ -55,28 +55,8 @@ export declare const constantChain: {
|
|
55
55
|
usdc: string;
|
56
56
|
weth: string;
|
57
57
|
wstETH: string;
|
58
|
-
|
59
|
-
|
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
|
-
} | {
|
58
|
+
};
|
59
|
+
[ChainId.ARBITRUM]: {
|
80
60
|
arb: string;
|
81
61
|
chr: string;
|
82
62
|
convexProxy: string;
|
@@ -90,38 +70,8 @@ export declare const constantChain: {
|
|
90
70
|
sliz: string;
|
91
71
|
stakeEndpoint: string;
|
92
72
|
usdc: string;
|
93
|
-
|
94
|
-
|
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
|
-
} | {
|
73
|
+
};
|
74
|
+
[ChainId.OPTIMISM]: {
|
125
75
|
jeur: string;
|
126
76
|
mai: string;
|
127
77
|
op: string;
|
@@ -129,89 +79,12 @@ export declare const constantChain: {
|
|
129
79
|
usdce: string;
|
130
80
|
velo: string;
|
131
81
|
veloV2: string;
|
132
|
-
|
133
|
-
|
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
|
-
} | {
|
82
|
+
};
|
83
|
+
[ChainId.BASE]: {
|
170
84
|
aero: string;
|
171
85
|
usdc: string;
|
172
|
-
|
173
|
-
|
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
|
-
} | {
|
86
|
+
};
|
87
|
+
[ChainId.POLYGON]: {
|
215
88
|
am3CRV: string;
|
216
89
|
amDAI: string;
|
217
90
|
amUSDC: string;
|
@@ -220,132 +93,13 @@ export declare const constantChain: {
|
|
220
93
|
jrt: string;
|
221
94
|
oretro: string;
|
222
95
|
usdc: string;
|
223
|
-
|
224
|
-
|
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
|
-
} | {
|
96
|
+
};
|
97
|
+
[ChainId.AVALANCHE]: {
|
260
98
|
glcr: string;
|
261
99
|
usdc: string;
|
262
|
-
|
263
|
-
|
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
|
-
} | {
|
100
|
+
};
|
101
|
+
[ChainId.BSC]: {
|
305
102
|
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;
|
349
103
|
};
|
350
104
|
};
|
351
105
|
export declare const MAVERICK_ZKSYNC_BP_LENS_ADDRESS = "0xd32CE31CaC98CAC0631764B8286358c0606D87F9";
|
package/dist/src/eden/index.d.ts
CHANGED
@@ -1643,28 +1643,6 @@ declare const eden: {
|
|
1643
1643
|
200: void;
|
1644
1644
|
}>>;
|
1645
1645
|
};
|
1646
|
-
pendings: {
|
1647
|
-
post: (body: {
|
1648
|
-
data: {
|
1649
|
-
reason: string;
|
1650
|
-
pending: string;
|
1651
|
-
recipient: string;
|
1652
|
-
}[];
|
1653
|
-
distributionChainId: number;
|
1654
|
-
campaignId: string;
|
1655
|
-
root: string;
|
1656
|
-
rewardToken: string;
|
1657
|
-
}, options: {
|
1658
|
-
headers: {
|
1659
|
-
authorization: string;
|
1660
|
-
};
|
1661
|
-
query?: Record<string, unknown> | undefined;
|
1662
|
-
fetch?: RequestInit | undefined;
|
1663
|
-
}) => Promise<import("@elysiajs/eden").Treaty.TreatyResponse<{
|
1664
|
-
[x: string]: any;
|
1665
|
-
200: any;
|
1666
|
-
}>>;
|
1667
|
-
};
|
1668
1646
|
};
|
1669
1647
|
unclaim: {
|
1670
1648
|
index: {
|
@@ -4765,28 +4743,6 @@ declare const eden: {
|
|
4765
4743
|
200: void;
|
4766
4744
|
}>>;
|
4767
4745
|
};
|
4768
|
-
pendings: {
|
4769
|
-
post: (body: {
|
4770
|
-
data: {
|
4771
|
-
reason: string;
|
4772
|
-
pending: string;
|
4773
|
-
recipient: string;
|
4774
|
-
}[];
|
4775
|
-
distributionChainId: number;
|
4776
|
-
campaignId: string;
|
4777
|
-
root: string;
|
4778
|
-
rewardToken: string;
|
4779
|
-
}, options: {
|
4780
|
-
headers: {
|
4781
|
-
authorization: string;
|
4782
|
-
};
|
4783
|
-
query?: Record<string, unknown> | undefined;
|
4784
|
-
fetch?: RequestInit | undefined;
|
4785
|
-
}) => Promise<import("@elysiajs/eden").Treaty.TreatyResponse<{
|
4786
|
-
[x: string]: any;
|
4787
|
-
200: any;
|
4788
|
-
}>>;
|
4789
|
-
};
|
4790
4746
|
};
|
4791
4747
|
unclaim: {
|
4792
4748
|
index: {
|
@@ -8886,33 +8842,6 @@ export declare const MerklApi: (domain: string | import("elysia").default<"", fa
|
|
8886
8842
|
};
|
8887
8843
|
};
|
8888
8844
|
};
|
8889
|
-
} & {
|
8890
|
-
engine: {
|
8891
|
-
pendings: {
|
8892
|
-
post: {
|
8893
|
-
body: {
|
8894
|
-
data: {
|
8895
|
-
reason: string;
|
8896
|
-
pending: string;
|
8897
|
-
recipient: string;
|
8898
|
-
}[];
|
8899
|
-
distributionChainId: number;
|
8900
|
-
campaignId: string;
|
8901
|
-
root: string;
|
8902
|
-
rewardToken: string;
|
8903
|
-
};
|
8904
|
-
params: {};
|
8905
|
-
query: unknown;
|
8906
|
-
headers: {
|
8907
|
-
authorization: string;
|
8908
|
-
};
|
8909
|
-
response: {
|
8910
|
-
[x: string]: any;
|
8911
|
-
200: any;
|
8912
|
-
};
|
8913
|
-
};
|
8914
|
-
};
|
8915
|
-
};
|
8916
8845
|
} & {
|
8917
8846
|
count: {
|
8918
8847
|
chain: {
|
@@ -13365,28 +13294,6 @@ export declare const MerklApi: (domain: string | import("elysia").default<"", fa
|
|
13365
13294
|
200: void;
|
13366
13295
|
}>>;
|
13367
13296
|
};
|
13368
|
-
pendings: {
|
13369
|
-
post: (body: {
|
13370
|
-
data: {
|
13371
|
-
reason: string;
|
13372
|
-
pending: string;
|
13373
|
-
recipient: string;
|
13374
|
-
}[];
|
13375
|
-
distributionChainId: number;
|
13376
|
-
campaignId: string;
|
13377
|
-
root: string;
|
13378
|
-
rewardToken: string;
|
13379
|
-
}, options: {
|
13380
|
-
headers: {
|
13381
|
-
authorization: string;
|
13382
|
-
};
|
13383
|
-
query?: Record<string, unknown> | undefined;
|
13384
|
-
fetch?: RequestInit | undefined;
|
13385
|
-
}) => Promise<import("@elysiajs/eden").Treaty.TreatyResponse<{
|
13386
|
-
[x: string]: any;
|
13387
|
-
200: any;
|
13388
|
-
}>>;
|
13389
|
-
};
|
13390
13297
|
};
|
13391
13298
|
unclaim: {
|
13392
13299
|
index: {
|
@@ -16487,28 +16394,6 @@ export declare const MerklApi: (domain: string | import("elysia").default<"", fa
|
|
16487
16394
|
200: void;
|
16488
16395
|
}>>;
|
16489
16396
|
};
|
16490
|
-
pendings: {
|
16491
|
-
post: (body: {
|
16492
|
-
data: {
|
16493
|
-
reason: string;
|
16494
|
-
pending: string;
|
16495
|
-
recipient: string;
|
16496
|
-
}[];
|
16497
|
-
distributionChainId: number;
|
16498
|
-
campaignId: string;
|
16499
|
-
root: string;
|
16500
|
-
rewardToken: string;
|
16501
|
-
}, options: {
|
16502
|
-
headers: {
|
16503
|
-
authorization: string;
|
16504
|
-
};
|
16505
|
-
query?: Record<string, unknown> | undefined;
|
16506
|
-
fetch?: RequestInit | undefined;
|
16507
|
-
}) => Promise<import("@elysiajs/eden").Treaty.TreatyResponse<{
|
16508
|
-
[x: string]: any;
|
16509
|
-
200: any;
|
16510
|
-
}>>;
|
16511
|
-
};
|
16512
16397
|
};
|
16513
16398
|
unclaim: {
|
16514
16399
|
index: {
|
package/dist/src/index.d.ts
CHANGED
@@ -1944,33 +1944,6 @@ declare const app: Elysia<"", false, {
|
|
1944
1944
|
};
|
1945
1945
|
};
|
1946
1946
|
};
|
1947
|
-
} & {
|
1948
|
-
engine: {
|
1949
|
-
pendings: {
|
1950
|
-
post: {
|
1951
|
-
body: {
|
1952
|
-
data: {
|
1953
|
-
reason: string;
|
1954
|
-
pending: string;
|
1955
|
-
recipient: string;
|
1956
|
-
}[];
|
1957
|
-
distributionChainId: number;
|
1958
|
-
campaignId: string;
|
1959
|
-
root: string;
|
1960
|
-
rewardToken: string;
|
1961
|
-
};
|
1962
|
-
params: {};
|
1963
|
-
query: unknown;
|
1964
|
-
headers: {
|
1965
|
-
authorization: string;
|
1966
|
-
};
|
1967
|
-
response: {
|
1968
|
-
[x: string]: any;
|
1969
|
-
200: any;
|
1970
|
-
};
|
1971
|
-
};
|
1972
|
-
};
|
1973
|
-
};
|
1974
1947
|
} & {
|
1975
1948
|
count: {
|
1976
1949
|
chain: {
|
@@ -3,7 +3,7 @@ if (!process.env.ENV || !process.env.FILENAME)
|
|
3
3
|
throw new Error("[ENV]: missing variable");
|
4
4
|
import { log } from "../../utils/logger";
|
5
5
|
import { apiDbClient } from "../../utils/prisma";
|
6
|
-
import { withRetry } from "@sdk";
|
6
|
+
import { NETWORK_LABELS, withRetry } from "@sdk";
|
7
7
|
import { S3Client } from "bun";
|
8
8
|
import moment from "moment";
|
9
9
|
// ─── Constants ───────────────────────────────────────────────
|
@@ -36,12 +36,14 @@ const extract = async () => {
|
|
36
36
|
}
|
37
37
|
if (data.length < MAX_BATCH_SIZE)
|
38
38
|
continue;
|
39
|
+
// Retry up to 5 times with a 10s delay
|
39
40
|
const promise = withRetry(load, [data], 5, 10_000);
|
40
41
|
loadPromises.push(promise);
|
41
42
|
await promise;
|
42
43
|
data = [];
|
43
44
|
}
|
44
45
|
// Final batch
|
46
|
+
// Retry up to 5 times with a 10s delay
|
45
47
|
const promise = withRetry(load, [data], 5, 10_000);
|
46
48
|
loadPromises.push(promise);
|
47
49
|
await promise;
|
@@ -61,7 +63,7 @@ const extract = async () => {
|
|
61
63
|
};
|
62
64
|
// ─── Transform & Load ────────────────────────────────────────────────────────
|
63
65
|
const load = async (pendings) => {
|
64
|
-
log.info(`pushing ${pendings.length} pendings`);
|
66
|
+
log.info(`pushing ${pendings.length} pendings for token ${pendings[0].rewardToken} on ${NETWORK_LABELS[chainId]}`);
|
65
67
|
const { updated, created } = await updatePendings({
|
66
68
|
distributionChainId: chainId,
|
67
69
|
rewardToken: pendings[0].rewardToken, // sometimes undefined
|
@@ -75,25 +77,12 @@ const load = async (pendings) => {
|
|
75
77
|
const updatePendings = async (data) => {
|
76
78
|
const rewardTokenId = Bun.hash(`${data.distributionChainId}${data.rewardToken}`).toString();
|
77
79
|
const campaignId = Bun.hash(`${data.distributionChainId}${data.campaignId}`).toString();
|
78
|
-
|
79
|
-
// Adds a record to the Reward row where pendings need to be updated
|
80
|
-
const updateRewardUniques = (recipient, pending, previousPending) => {
|
81
|
-
Bun.hash(`${root}${recipient}${rewardTokenId}`).toString();
|
82
|
-
const rewardId = Bun.hash(`${data.root}${recipient}${rewardTokenId}`).toString();
|
83
|
-
if (!rewardUniques[rewardId]) {
|
84
|
-
rewardUniques[rewardId] = { pending: "0", recipient: recipient };
|
85
|
-
}
|
86
|
-
rewardUniques[rewardId].pending = (BigInt(rewardUniques[rewardId].pending) +
|
87
|
-
BigInt(pending) -
|
88
|
-
BigInt(previousPending ?? "0")) // Store the delta
|
89
|
-
.toString();
|
90
|
-
};
|
80
|
+
// List of identifiers of breakdowns that will be touched by this jobd
|
91
81
|
const breakdownUniques = await data.data.map(({ recipient, reason }) => {
|
92
82
|
const rewardId = Bun.hash(`${data.root}${recipient}${rewardTokenId}`).toString();
|
93
83
|
return { rewardId, reason, campaignId };
|
94
84
|
});
|
95
|
-
|
96
|
-
const breakdownToCreate = [];
|
85
|
+
// Check if these breakdowns already exist or not
|
97
86
|
const breakdownExists = await apiDbClient.$transaction(breakdownUniques.map(x => apiDbClient.rewardBreakdown.findUnique({
|
98
87
|
select: {
|
99
88
|
pending: true,
|
@@ -106,20 +95,35 @@ const updatePendings = async (data) => {
|
|
106
95
|
},
|
107
96
|
},
|
108
97
|
})));
|
98
|
+
// We want to get all current pendings for the rewardIds that will be modified
|
99
|
+
// Should contain rewardId => { pendingIncrease, recipient }
|
100
|
+
const rewardIdToPendingIncrease = {};
|
101
|
+
const breakdownToUpdate = [];
|
102
|
+
const breakdownToCreate = [];
|
103
|
+
let totalBreakdownIncrease = 0n;
|
104
|
+
// For all point to update
|
105
|
+
// - compute the delta with what's in database, add it to rewardIdToPendingIncrease
|
106
|
+
// - add the point to breakdownToUpdate or breakdownToCreate
|
109
107
|
for (const [pointIndex, point] of data.data.entries()) {
|
110
|
-
|
111
|
-
if (
|
112
|
-
|
108
|
+
const rewardId = Bun.hash(`${data.root}${point.recipient}${rewardTokenId}`).toString();
|
109
|
+
if (!rewardIdToPendingIncrease[rewardId]) {
|
110
|
+
rewardIdToPendingIncrease[rewardId] = { pendingIncrease: 0n, recipient: point.recipient };
|
111
|
+
}
|
112
|
+
const delta = BigInt(point.pending) - BigInt(breakdownExists[pointIndex]?.pending ?? "0");
|
113
|
+
totalBreakdownIncrease += delta;
|
114
|
+
if (delta > 0n) {
|
115
|
+
rewardIdToPendingIncrease[rewardId].pendingIncrease += delta; // Store the delta
|
116
|
+
if (!!breakdownExists[pointIndex]) {
|
113
117
|
breakdownToUpdate.push(point);
|
114
118
|
}
|
115
|
-
|
116
|
-
|
117
|
-
|
119
|
+
else {
|
120
|
+
breakdownToCreate.push(point);
|
121
|
+
}
|
118
122
|
}
|
119
123
|
}
|
120
|
-
const
|
121
|
-
const
|
122
|
-
const
|
124
|
+
const rewardToUpdate = [];
|
125
|
+
const rewardToCreate = [];
|
126
|
+
const RewardExists = await apiDbClient.$transaction(Object.keys(rewardIdToPendingIncrease).map(x => apiDbClient.reward.findUnique({
|
123
127
|
select: {
|
124
128
|
pending: true,
|
125
129
|
},
|
@@ -127,25 +131,29 @@ const updatePendings = async (data) => {
|
|
127
131
|
id: x,
|
128
132
|
},
|
129
133
|
})));
|
130
|
-
for (const [pointIndex, point] of Object.values(
|
131
|
-
if (
|
132
|
-
if (
|
133
|
-
|
134
|
-
|
135
|
-
pending:
|
134
|
+
for (const [pointIndex, point] of Object.values(rewardIdToPendingIncrease).entries()) {
|
135
|
+
if (BigInt(point.pendingIncrease) > 0n) {
|
136
|
+
if (!!RewardExists[pointIndex]) {
|
137
|
+
rewardToUpdate.push({
|
138
|
+
recipient: point.recipient,
|
139
|
+
pending: BigInt(RewardExists[pointIndex].pending) + BigInt(point.pendingIncrease),
|
140
|
+
});
|
141
|
+
}
|
142
|
+
else {
|
143
|
+
rewardToCreate.push({
|
144
|
+
recipient: point.recipient,
|
145
|
+
pending: BigInt(point.pendingIncrease),
|
136
146
|
});
|
137
147
|
}
|
138
|
-
}
|
139
|
-
else {
|
140
|
-
toCreate.push(point);
|
141
148
|
}
|
142
149
|
}
|
143
|
-
|
144
|
-
|
145
|
-
|
150
|
+
const totalRewardIncrease = Object.values(rewardIdToPendingIncrease).reduce((prev, current) => prev + BigInt(current.pendingIncrease), 0n);
|
151
|
+
log.info(`rewards to create: ${rewardToCreate.length}, to update: ${rewardToUpdate.length}, total reward increase: ${totalRewardIncrease.toString()}`);
|
152
|
+
if (rewardToCreate.length > 0) {
|
153
|
+
const users = rewardToCreate.map(x => x.recipient);
|
146
154
|
await apiDbClient.user.createMany({ data: users.map(x => ({ address: x, tags: [] })), skipDuplicates: true });
|
147
155
|
await apiDbClient.reward.createMany({
|
148
|
-
data:
|
156
|
+
data: rewardToCreate.map(x => {
|
149
157
|
const rewardId = Bun.hash(`${root}${x.recipient}${rewardTokenId}`).toString();
|
150
158
|
return {
|
151
159
|
id: rewardId,
|
@@ -154,26 +162,26 @@ const updatePendings = async (data) => {
|
|
154
162
|
rewardTokenId,
|
155
163
|
proofs: [],
|
156
164
|
amount: "0",
|
157
|
-
pending: x.pending,
|
165
|
+
pending: x.pending.toString(),
|
158
166
|
claimed: "0",
|
159
167
|
};
|
160
168
|
}),
|
161
169
|
});
|
162
170
|
}
|
163
|
-
if (
|
164
|
-
await apiDbClient.$transaction(
|
171
|
+
if (rewardToUpdate.length > 0) {
|
172
|
+
await apiDbClient.$transaction(rewardToUpdate.map(x => {
|
165
173
|
const rewardId = Bun.hash(`${data.root}${x.recipient}${rewardTokenId}`).toString();
|
166
174
|
return apiDbClient.reward.update({
|
167
175
|
where: {
|
168
176
|
id: rewardId,
|
169
177
|
},
|
170
178
|
data: {
|
171
|
-
pending: x.pending,
|
179
|
+
pending: x.pending.toString(),
|
172
180
|
},
|
173
181
|
});
|
174
182
|
}));
|
175
183
|
}
|
176
|
-
|
184
|
+
log.info(`breakdowns to create: ${breakdownToCreate.length}, to update: ${breakdownToUpdate.length}, total breakdown increase: ${totalBreakdownIncrease.toString()}`);
|
177
185
|
if (breakdownToUpdate.length > 0) {
|
178
186
|
await apiDbClient.$transaction(breakdownToUpdate.map(x => {
|
179
187
|
return apiDbClient.rewardBreakdown.update({
|