@merkl/api 0.10.311 → 0.10.312
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/eden/index.d.ts +18 -12
- package/dist/src/index.d.ts +6 -4
- package/dist/src/modules/v4/explorer/explorer.controller.js +1 -1
- package/dist/src/modules/v4/reward/reward.controller.d.ts +6 -4
- package/dist/src/modules/v4/reward/reward.controller.js +7 -2
- package/dist/src/modules/v4/reward/reward.repository.d.ts +4 -10
- package/dist/src/modules/v4/reward/reward.repository.js +18 -9
- package/dist/src/modules/v4/reward/reward.service.d.ts +6 -4
- package/dist/src/modules/v4/reward/reward.service.js +26 -32
- package/dist/src/modules/v4/router.d.ts +6 -4
- package/dist/tsconfig.package.tsbuildinfo +1 -1
- package/package.json +3 -1
package/dist/src/eden/index.d.ts
CHANGED
@@ -1097,18 +1097,20 @@ declare const eden: {
|
|
1097
1097
|
count: number;
|
1098
1098
|
};
|
1099
1099
|
}>>;
|
1100
|
-
|
1100
|
+
chain: {
|
1101
1101
|
get: (options: {
|
1102
1102
|
headers: {
|
1103
1103
|
authorization: string;
|
1104
1104
|
};
|
1105
|
-
query
|
1105
|
+
query: {
|
1106
|
+
chainId: number;
|
1107
|
+
};
|
1106
1108
|
fetch?: RequestInit | undefined;
|
1107
1109
|
}) => Promise<import("@elysiajs/eden").Treaty.TreatyResponse<{
|
1108
1110
|
200: {
|
1109
1111
|
[x: string]: {
|
1110
|
-
|
1111
|
-
|
1112
|
+
rewardCount: number;
|
1113
|
+
breakdownCount: number;
|
1112
1114
|
};
|
1113
1115
|
};
|
1114
1116
|
}>>;
|
@@ -4399,19 +4401,21 @@ export declare const MerklApi: (domain: string | import("elysia").default<"", fa
|
|
4399
4401
|
};
|
4400
4402
|
} & {
|
4401
4403
|
count: {
|
4402
|
-
|
4404
|
+
chain: {
|
4403
4405
|
get: {
|
4404
4406
|
body: unknown;
|
4405
4407
|
params: {};
|
4406
|
-
query:
|
4408
|
+
query: {
|
4409
|
+
chainId: number;
|
4410
|
+
};
|
4407
4411
|
headers: {
|
4408
4412
|
authorization: string;
|
4409
4413
|
};
|
4410
4414
|
response: {
|
4411
4415
|
200: {
|
4412
4416
|
[x: string]: {
|
4413
|
-
|
4414
|
-
|
4417
|
+
rewardCount: number;
|
4418
|
+
breakdownCount: number;
|
4415
4419
|
};
|
4416
4420
|
};
|
4417
4421
|
};
|
@@ -7674,18 +7678,20 @@ export declare const MerklApi: (domain: string | import("elysia").default<"", fa
|
|
7674
7678
|
count: number;
|
7675
7679
|
};
|
7676
7680
|
}>>;
|
7677
|
-
|
7681
|
+
chain: {
|
7678
7682
|
get: (options: {
|
7679
7683
|
headers: {
|
7680
7684
|
authorization: string;
|
7681
7685
|
};
|
7682
|
-
query
|
7686
|
+
query: {
|
7687
|
+
chainId: number;
|
7688
|
+
};
|
7683
7689
|
fetch?: RequestInit | undefined;
|
7684
7690
|
}) => Promise<import("@elysiajs/eden").Treaty.TreatyResponse<{
|
7685
7691
|
200: {
|
7686
7692
|
[x: string]: {
|
7687
|
-
|
7688
|
-
|
7693
|
+
rewardCount: number;
|
7694
|
+
breakdownCount: number;
|
7689
7695
|
};
|
7690
7696
|
};
|
7691
7697
|
}>>;
|
package/dist/src/index.d.ts
CHANGED
@@ -1486,19 +1486,21 @@ declare const app: Elysia<"", false, {
|
|
1486
1486
|
};
|
1487
1487
|
} & {
|
1488
1488
|
count: {
|
1489
|
-
|
1489
|
+
chain: {
|
1490
1490
|
get: {
|
1491
1491
|
body: unknown;
|
1492
1492
|
params: {};
|
1493
|
-
query:
|
1493
|
+
query: {
|
1494
|
+
chainId: number;
|
1495
|
+
};
|
1494
1496
|
headers: {
|
1495
1497
|
authorization: string;
|
1496
1498
|
};
|
1497
1499
|
response: {
|
1498
1500
|
200: {
|
1499
1501
|
[x: string]: {
|
1500
|
-
|
1501
|
-
|
1502
|
+
rewardCount: number;
|
1503
|
+
breakdownCount: number;
|
1502
1504
|
};
|
1503
1505
|
};
|
1504
1506
|
};
|
@@ -4,7 +4,7 @@ import { ExplorerService } from ".";
|
|
4
4
|
import { CreateExplorerDto } from "./explorer.model";
|
5
5
|
// ─── Explorer Controller ───────────────────────────────────────────────────────
|
6
6
|
export const ExplorerController = new Elysia({ prefix: "/explorers", detail: { tags: ["Explorers"] } })
|
7
|
-
// ─── Create An Explorer
|
7
|
+
// ─── Create An Explorer ──────────────────────────────────────────────────────
|
8
8
|
.post("", async ({ body }) => await ExplorerService.create(body), {
|
9
9
|
beforeHandle: BackOfficeGuard,
|
10
10
|
headers: AuthorizationHeadersDto,
|
@@ -244,19 +244,21 @@ export declare const RewardController: Elysia<"/rewards", false, {
|
|
244
244
|
};
|
245
245
|
} & {
|
246
246
|
count: {
|
247
|
-
|
247
|
+
chain: {
|
248
248
|
get: {
|
249
249
|
body: unknown;
|
250
250
|
params: {};
|
251
|
-
query:
|
251
|
+
query: {
|
252
|
+
chainId: number;
|
253
|
+
};
|
252
254
|
headers: {
|
253
255
|
authorization: string;
|
254
256
|
};
|
255
257
|
response: {
|
256
258
|
200: {
|
257
259
|
[x: string]: {
|
258
|
-
|
259
|
-
|
260
|
+
rewardCount: number;
|
261
|
+
breakdownCount: number;
|
260
262
|
};
|
261
263
|
};
|
262
264
|
};
|
@@ -2,6 +2,7 @@ import { BackOfficeGuard } from "../../../guards/BackOffice.guard";
|
|
2
2
|
import { AuthorizationHeadersDto, EngineGuard } from "../../../guards/Engine.guard";
|
3
3
|
import { throwOnInvalidRequiredAddress, throwOnUnsupportedChainId } from "../../../utils/throw";
|
4
4
|
import Elysia from "elysia";
|
5
|
+
import { ChainDto } from "../accounting";
|
5
6
|
import { CampaignIdDto, CampaignIdWithoutPageDto, CreateManyBreakdownDto, CreateManyRewardDto, RegisterClaimsDto, TokenIdDto, UpdatePendingDto, } from "./reward.model";
|
6
7
|
import { RewardService } from "./reward.service";
|
7
8
|
// ─── Rewards Controller ──────────────────────────────────────────────────────
|
@@ -101,9 +102,13 @@ export const RewardController = new Elysia({ prefix: "/rewards", detail: { tags:
|
|
101
102
|
}));
|
102
103
|
})
|
103
104
|
// ─── Get Reward Count By Chain And Root ──────────────────────────────
|
104
|
-
.get("/count/
|
105
|
+
.get("/count/chain", async ({ query }) => await RewardService.countOnChain(query.chainId), {
|
106
|
+
query: ChainDto,
|
105
107
|
headers: AuthorizationHeadersDto,
|
106
|
-
beforeHandle:
|
108
|
+
beforeHandle: ({ headers, query }) => {
|
109
|
+
BackOfficeGuard({ headers });
|
110
|
+
throwOnUnsupportedChainId(query.chainId);
|
111
|
+
},
|
107
112
|
detail: { hide: true },
|
108
113
|
})
|
109
114
|
// ─── Unclaimed Data routes ───────────────────────────────────────────
|
@@ -121,16 +121,10 @@ export declare abstract class RewardRepository {
|
|
121
121
|
claimed: string;
|
122
122
|
proofs: string[];
|
123
123
|
}) | null>;
|
124
|
-
static
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
})[]>;
|
129
|
-
static countRewardBreakdownPerCampaignId(): Promise<(Prisma.PickEnumerable<Prisma.RewardBreakdownGroupByOutputType, "campaignId"[]> & {
|
130
|
-
_count: {
|
131
|
-
_all: number;
|
132
|
-
};
|
133
|
-
})[]>;
|
124
|
+
static countRewardAndBreakdownOnChain(chainId: number, root: string): Promise<{
|
125
|
+
rewardCount: number;
|
126
|
+
breakdownCount: number;
|
127
|
+
}>;
|
134
128
|
static updateClaimed(recipient: string, rewardTokenId: string, campaignId: string, reason: string, amount: string): Promise<Prisma.BatchPayload>;
|
135
129
|
static findManyBreakdownUniques(uniques: {
|
136
130
|
rewardId: string;
|
@@ -115,17 +115,26 @@ export class RewardRepository {
|
|
115
115
|
},
|
116
116
|
});
|
117
117
|
}
|
118
|
-
static async
|
119
|
-
|
120
|
-
|
121
|
-
|
118
|
+
static async countRewardAndBreakdownOnChain(chainId, root) {
|
119
|
+
const rewardCount = await apiDbClient.reward.count({
|
120
|
+
where: {
|
121
|
+
root,
|
122
|
+
RewardToken: {
|
123
|
+
chainId,
|
124
|
+
},
|
125
|
+
},
|
122
126
|
});
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
127
|
+
const breakdownCount = await apiDbClient.rewardBreakdown.count({
|
128
|
+
where: {
|
129
|
+
Reward: {
|
130
|
+
root,
|
131
|
+
RewardToken: {
|
132
|
+
chainId,
|
133
|
+
},
|
134
|
+
},
|
135
|
+
},
|
128
136
|
});
|
137
|
+
return { rewardCount, breakdownCount };
|
129
138
|
}
|
130
139
|
static async updateClaimed(recipient, rewardTokenId, campaignId, reason, amount) {
|
131
140
|
return await apiDbClient.rewardBreakdown.updateMany({
|
@@ -558,10 +558,12 @@ export declare abstract class RewardService {
|
|
558
558
|
created: number;
|
559
559
|
updated: number;
|
560
560
|
}>;
|
561
|
-
static
|
562
|
-
|
563
|
-
|
564
|
-
|
561
|
+
static countOnChain(chainId: number): Promise<{
|
562
|
+
[x: string]: {
|
563
|
+
rewardCount: number;
|
564
|
+
breakdownCount: number;
|
565
|
+
};
|
566
|
+
}>;
|
565
567
|
static breakdownForCampaign(query: CampaignIdModel): Promise<import("./reward.model").BreakdownForCampaignsRaw[]>;
|
566
568
|
static countForCampaign(query: CampaignIdModel): Promise<{
|
567
569
|
count: number;
|
@@ -287,29 +287,17 @@ export class RewardService {
|
|
287
287
|
await RewardRepository.createBreakdownPendings(rewardTokenId, data.root, campaignId, breakdownToCreate);
|
288
288
|
return { created: breakdownToCreate.length, updated: breakdownToUpdate.length };
|
289
289
|
}
|
290
|
-
static async
|
291
|
-
const
|
292
|
-
const
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
res[NETWORK_LABELS[chainId]] = { rewards: {}, breakdown: 0 };
|
302
|
-
if (!res[NETWORK_LABELS[chainId]].rewards[root])
|
303
|
-
res[NETWORK_LABELS[chainId]].rewards[root] = 0;
|
304
|
-
res[NETWORK_LABELS[chainId]].rewards[root] += _count._all;
|
305
|
-
}
|
306
|
-
for (const { _count, campaignId } of rewardBreakdownPerCampaignId) {
|
307
|
-
const chainId = campaignIdToChain[campaignId];
|
308
|
-
if (!chainId)
|
309
|
-
continue;
|
310
|
-
res[NETWORK_LABELS[chainId]].breakdown += _count._all;
|
311
|
-
}
|
312
|
-
return res;
|
290
|
+
static async countOnChain(chainId) {
|
291
|
+
const roots = await MerklRootService.fetch(chainId);
|
292
|
+
const promises = [
|
293
|
+
RewardRepository.countRewardAndBreakdownOnChain(chainId, roots.tree),
|
294
|
+
RewardRepository.countRewardAndBreakdownOnChain(chainId, roots.lastTree),
|
295
|
+
];
|
296
|
+
await Promise.all(promises);
|
297
|
+
return {
|
298
|
+
[roots.tree]: await promises[0],
|
299
|
+
[roots.lastTree]: await promises[1],
|
300
|
+
};
|
313
301
|
}
|
314
302
|
static async breakdownForCampaign(query) {
|
315
303
|
const root = await MerklRootService.fetch(query.chainId);
|
@@ -326,19 +314,25 @@ export class RewardService {
|
|
326
314
|
return RewardRepository.totalForCampaign(CampaignService.hashId({ distributionChain: query.chainId, campaignId: query.campaignId }), root.live);
|
327
315
|
}
|
328
316
|
static async breakdownForToken(query) {
|
329
|
-
|
330
|
-
|
331
|
-
|
317
|
+
return CacheService.wrap(TTLPresets.MIN_10, async (query) => {
|
318
|
+
const root = await MerklRootService.fetch(query.chainId);
|
319
|
+
const id = TokenService.hashId({ chainId: query.chainId, address: query.address });
|
320
|
+
return RewardRepository.breakdownForToken(root.live, id, query);
|
321
|
+
}, query);
|
332
322
|
}
|
333
323
|
static async countForToken(query) {
|
334
|
-
|
335
|
-
|
336
|
-
|
324
|
+
return CacheService.wrap(TTLPresets.MIN_10, async (query) => {
|
325
|
+
const root = await MerklRootService.fetch(query.chainId);
|
326
|
+
const id = TokenService.hashId({ chainId: query.chainId, address: query.address });
|
327
|
+
return RewardRepository.countForToken(id, root.live);
|
328
|
+
}, query);
|
337
329
|
}
|
338
330
|
static async totalForToken(query) {
|
339
|
-
|
340
|
-
|
341
|
-
|
331
|
+
return CacheService.wrap(TTLPresets.MIN_10, async (query) => {
|
332
|
+
const root = await MerklRootService.fetch(query.chainId);
|
333
|
+
const id = TokenService.hashId({ chainId: query.chainId, address: query.address });
|
334
|
+
return RewardRepository.totalForToken(id, root.live);
|
335
|
+
}, query);
|
342
336
|
}
|
343
337
|
static async getAmountAndClaimedForCampaigns(x) {
|
344
338
|
const currentRoot = await MerklRootService.fetch(x.chainId);
|
@@ -1364,19 +1364,21 @@ export declare const v4: Elysia<"/v4", false, {
|
|
1364
1364
|
};
|
1365
1365
|
} & {
|
1366
1366
|
count: {
|
1367
|
-
|
1367
|
+
chain: {
|
1368
1368
|
get: {
|
1369
1369
|
body: unknown;
|
1370
1370
|
params: {};
|
1371
|
-
query:
|
1371
|
+
query: {
|
1372
|
+
chainId: number;
|
1373
|
+
};
|
1372
1374
|
headers: {
|
1373
1375
|
authorization: string;
|
1374
1376
|
};
|
1375
1377
|
response: {
|
1376
1378
|
200: {
|
1377
1379
|
[x: string]: {
|
1378
|
-
|
1379
|
-
|
1380
|
+
rewardCount: number;
|
1381
|
+
breakdownCount: number;
|
1380
1382
|
};
|
1381
1383
|
};
|
1382
1384
|
};
|