@merkl/api 0.10.408 → 0.10.409
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 +10 -20
- package/dist/src/index.d.ts +2 -4
- package/dist/src/modules/v4/reward/reward.controller.d.ts +2 -4
- package/dist/src/modules/v4/reward/reward.repository.d.ts +1 -57
- package/dist/src/modules/v4/reward/reward.repository.js +0 -93
- package/dist/src/modules/v4/reward/reward.service.d.ts +1 -5
- package/dist/src/modules/v4/reward/reward.service.js +5 -56
- package/dist/src/modules/v4/router.d.ts +2 -4
- package/dist/tsconfig.package.tsbuildinfo +1 -1
- package/package.json +1 -1
package/dist/src/eden/index.d.ts
CHANGED
@@ -1631,10 +1631,8 @@ declare const eden: {
|
|
1631
1631
|
query?: Record<string, unknown> | undefined;
|
1632
1632
|
fetch?: RequestInit | undefined;
|
1633
1633
|
}) => Promise<import("@elysiajs/eden").Treaty.TreatyResponse<{
|
1634
|
-
|
1635
|
-
|
1636
|
-
updated: number;
|
1637
|
-
};
|
1634
|
+
[x: string]: any;
|
1635
|
+
200: any;
|
1638
1636
|
}>>;
|
1639
1637
|
};
|
1640
1638
|
};
|
@@ -4634,10 +4632,8 @@ declare const eden: {
|
|
4634
4632
|
query?: Record<string, unknown> | undefined;
|
4635
4633
|
fetch?: RequestInit | undefined;
|
4636
4634
|
}) => Promise<import("@elysiajs/eden").Treaty.TreatyResponse<{
|
4637
|
-
|
4638
|
-
|
4639
|
-
updated: number;
|
4640
|
-
};
|
4635
|
+
[x: string]: any;
|
4636
|
+
200: any;
|
4641
4637
|
}>>;
|
4642
4638
|
};
|
4643
4639
|
};
|
@@ -8625,10 +8621,8 @@ export declare const MerklApi: (domain: string | import("elysia").default<"", fa
|
|
8625
8621
|
authorization: string;
|
8626
8622
|
};
|
8627
8623
|
response: {
|
8628
|
-
|
8629
|
-
|
8630
|
-
updated: number;
|
8631
|
-
};
|
8624
|
+
[x: string]: any;
|
8625
|
+
200: any;
|
8632
8626
|
};
|
8633
8627
|
};
|
8634
8628
|
};
|
@@ -12944,10 +12938,8 @@ export declare const MerklApi: (domain: string | import("elysia").default<"", fa
|
|
12944
12938
|
query?: Record<string, unknown> | undefined;
|
12945
12939
|
fetch?: RequestInit | undefined;
|
12946
12940
|
}) => Promise<import("@elysiajs/eden").Treaty.TreatyResponse<{
|
12947
|
-
|
12948
|
-
|
12949
|
-
updated: number;
|
12950
|
-
};
|
12941
|
+
[x: string]: any;
|
12942
|
+
200: any;
|
12951
12943
|
}>>;
|
12952
12944
|
};
|
12953
12945
|
};
|
@@ -15947,10 +15939,8 @@ export declare const MerklApi: (domain: string | import("elysia").default<"", fa
|
|
15947
15939
|
query?: Record<string, unknown> | undefined;
|
15948
15940
|
fetch?: RequestInit | undefined;
|
15949
15941
|
}) => Promise<import("@elysiajs/eden").Treaty.TreatyResponse<{
|
15950
|
-
|
15951
|
-
|
15952
|
-
updated: number;
|
15953
|
-
};
|
15942
|
+
[x: string]: any;
|
15943
|
+
200: any;
|
15954
15944
|
}>>;
|
15955
15945
|
};
|
15956
15946
|
};
|
package/dist/src/index.d.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import type { ChainId } from "@sdk";
|
2
|
-
import type { BreakdownForCampaignsRaw, CampaignIdModel, CampaignIdWithoutPageModel, CreateManyBreakdownModel, CreateManyRewardModel,
|
2
|
+
import type { BreakdownForCampaignsRaw, CampaignIdModel, CampaignIdWithoutPageModel, CreateManyBreakdownModel, CreateManyRewardModel, TokenIdModel } from "./reward.model";
|
3
3
|
export declare abstract class RewardRepository {
|
4
4
|
static createManyReward(rewards: CreateManyRewardModel): Promise<import("database/api/.generated/runtime/library").GetBatchResult>;
|
5
5
|
static createManyBreakdown(data: CreateManyBreakdownModel): Promise<import("database/api/.generated/runtime/library").GetBatchResult>;
|
@@ -122,62 +122,6 @@ export declare abstract class RewardRepository {
|
|
122
122
|
}>;
|
123
123
|
static updateRewardClaimed(recipient: string, rewardTokenId: string, amount: string): Promise<import("database/api/.generated/runtime/library").GetBatchResult>;
|
124
124
|
static updateBreakdownClaimed(recipient: string, rewardTokenId: string, campaignId: string, reason: string, amount: string): Promise<import("database/api/.generated/runtime/library").GetBatchResult>;
|
125
|
-
static findManyBreakdownUniques(uniques: {
|
126
|
-
rewardId: string;
|
127
|
-
campaignId: string;
|
128
|
-
reason: string;
|
129
|
-
}[]): Promise<({
|
130
|
-
pending: string;
|
131
|
-
} | null)[]>;
|
132
|
-
static findManyRewardUniques(rewardIds: string[]): Promise<({
|
133
|
-
pending: string;
|
134
|
-
} | null)[]>;
|
135
|
-
static updateRewardPendings(rewardTokenId: string, root: string, toUpdate: {
|
136
|
-
recipient: string;
|
137
|
-
pending: string;
|
138
|
-
}[]): Promise<{
|
139
|
-
pending: string;
|
140
|
-
id: string;
|
141
|
-
recipient: string;
|
142
|
-
rewardTokenId: string;
|
143
|
-
amount: string;
|
144
|
-
root: string;
|
145
|
-
claimed: string;
|
146
|
-
proofs: string[];
|
147
|
-
}[]>;
|
148
|
-
static updateBreakdownPendings(rewardTokenId: string, root: string, campaignId: string, toUpdate: PendingEntity[]): Promise<{
|
149
|
-
reason: string;
|
150
|
-
pending: string;
|
151
|
-
id: number;
|
152
|
-
campaignId: string;
|
153
|
-
amount: string;
|
154
|
-
claimed: string;
|
155
|
-
protocolId: string | null;
|
156
|
-
rewardId: string;
|
157
|
-
}[]>;
|
158
|
-
static createRewardPendings(rewardTokenId: string, root: string, toCreate: {
|
159
|
-
recipient: string;
|
160
|
-
pending: string;
|
161
|
-
}[]): Promise<{
|
162
|
-
pending: string;
|
163
|
-
id: string;
|
164
|
-
recipient: string;
|
165
|
-
rewardTokenId: string;
|
166
|
-
amount: string;
|
167
|
-
root: string;
|
168
|
-
claimed: string;
|
169
|
-
proofs: string[];
|
170
|
-
}[]>;
|
171
|
-
static createBreakdownPendings(rewardTokenId: string, root: string, campaignId: string, toCreate: PendingEntity[]): Promise<{
|
172
|
-
reason: string;
|
173
|
-
pending: string;
|
174
|
-
id: number;
|
175
|
-
campaignId: string;
|
176
|
-
amount: string;
|
177
|
-
claimed: string;
|
178
|
-
protocolId: string | null;
|
179
|
-
rewardId: string;
|
180
|
-
}[]>;
|
181
125
|
static findManyRootsWithRewardOnChain(chainId: number): Promise<string[]>;
|
182
126
|
static breakdownForCampaign(root: string, id: string, query: CampaignIdModel): Promise<BreakdownForCampaignsRaw[]>;
|
183
127
|
static totalForCampaign(campaignId: string, root: string): Promise<{
|
@@ -162,99 +162,6 @@ export class RewardRepository {
|
|
162
162
|
},
|
163
163
|
});
|
164
164
|
}
|
165
|
-
static async findManyBreakdownUniques(uniques) {
|
166
|
-
return await apiDbClient.$transaction(uniques.map(x => apiDbClient.rewardBreakdown.findUnique({
|
167
|
-
select: {
|
168
|
-
pending: true,
|
169
|
-
},
|
170
|
-
where: {
|
171
|
-
rewardId_campaignId_reason: {
|
172
|
-
rewardId: x.rewardId,
|
173
|
-
campaignId: x.campaignId,
|
174
|
-
reason: x.reason,
|
175
|
-
},
|
176
|
-
},
|
177
|
-
})));
|
178
|
-
}
|
179
|
-
static async findManyRewardUniques(rewardIds) {
|
180
|
-
return await apiDbClient.$transaction(rewardIds.map(x => apiDbClient.reward.findUnique({
|
181
|
-
select: {
|
182
|
-
pending: true,
|
183
|
-
},
|
184
|
-
where: {
|
185
|
-
id: x,
|
186
|
-
},
|
187
|
-
})));
|
188
|
-
}
|
189
|
-
static async updateRewardPendings(rewardTokenId, root, toUpdate) {
|
190
|
-
return await apiDbClient.$transaction(toUpdate.map(x => {
|
191
|
-
const rewardId = RewardService.hashId(root, x.recipient, rewardTokenId);
|
192
|
-
return apiDbClient.reward.update({
|
193
|
-
where: {
|
194
|
-
id: rewardId,
|
195
|
-
},
|
196
|
-
data: {
|
197
|
-
pending: x.pending,
|
198
|
-
},
|
199
|
-
});
|
200
|
-
}));
|
201
|
-
}
|
202
|
-
static async updateBreakdownPendings(rewardTokenId, root, campaignId, toUpdate) {
|
203
|
-
return await apiDbClient.$transaction(toUpdate.map(x => {
|
204
|
-
return apiDbClient.rewardBreakdown.update({
|
205
|
-
where: {
|
206
|
-
rewardId_campaignId_reason: {
|
207
|
-
rewardId: RewardService.hashId(root, x.recipient, rewardTokenId),
|
208
|
-
campaignId: campaignId,
|
209
|
-
reason: x.reason,
|
210
|
-
},
|
211
|
-
},
|
212
|
-
data: {
|
213
|
-
pending: x.pending,
|
214
|
-
},
|
215
|
-
});
|
216
|
-
}));
|
217
|
-
}
|
218
|
-
static async createRewardPendings(rewardTokenId, root, toCreate) {
|
219
|
-
const users = toCreate.map(x => x.recipient);
|
220
|
-
await UserService.createMany(users.map(x => ({ address: x, tags: [] })));
|
221
|
-
return await apiDbClient.$transaction(toCreate.map(x => {
|
222
|
-
const rewardId = RewardService.hashId(root, x.recipient, rewardTokenId);
|
223
|
-
return apiDbClient.reward.create({
|
224
|
-
data: {
|
225
|
-
id: rewardId,
|
226
|
-
MerklRoot: { connect: { root } },
|
227
|
-
User: { connect: { address: x.recipient } },
|
228
|
-
RewardToken: { connect: { id: rewardTokenId } },
|
229
|
-
proofs: [],
|
230
|
-
amount: "0",
|
231
|
-
pending: x.pending,
|
232
|
-
claimed: "0",
|
233
|
-
},
|
234
|
-
});
|
235
|
-
}));
|
236
|
-
}
|
237
|
-
static async createBreakdownPendings(rewardTokenId, root, campaignId, toCreate) {
|
238
|
-
const users = toCreate.map(x => x.recipient);
|
239
|
-
await UserService.createMany(users.map(x => ({ address: x, tags: [] })));
|
240
|
-
return await apiDbClient.$transaction(toCreate.map(x => {
|
241
|
-
const rewardId = RewardService.hashId(root, x.recipient, rewardTokenId);
|
242
|
-
return apiDbClient.rewardBreakdown.create({
|
243
|
-
data: {
|
244
|
-
reason: x.reason,
|
245
|
-
amount: "0",
|
246
|
-
pending: x.pending,
|
247
|
-
claimed: "0",
|
248
|
-
Reward: {
|
249
|
-
connect: {
|
250
|
-
id: rewardId,
|
251
|
-
},
|
252
|
-
},
|
253
|
-
Campaign: { connect: { id: campaignId } },
|
254
|
-
},
|
255
|
-
});
|
256
|
-
}));
|
257
|
-
}
|
258
165
|
static async findManyRootsWithRewardOnChain(chainId) {
|
259
166
|
return (await apiDbClient.merklRoot.findMany({
|
260
167
|
where: {
|
@@ -2,7 +2,7 @@ import type { CacheKeys } from "../../../cache/keys";
|
|
2
2
|
import type { Chain } from "../../../../database/api/.generated";
|
3
3
|
import { Campaign, type CampaignDynamicData, type ChainId, type MerklChainId } from "@sdk";
|
4
4
|
import { type LightOpportunityFromDB, type Opportunity } from "../opportunity";
|
5
|
-
import type { CampaignIdModel, CampaignIdWithoutPageModel, CreateManyBreakdownModel, CreateManyRewardModel, DailyRewardsRecord, RegisterClaimsModel, RewardBreakdown, TokenIdModel
|
5
|
+
import type { CampaignIdModel, CampaignIdWithoutPageModel, CreateManyBreakdownModel, CreateManyRewardModel, DailyRewardsRecord, RegisterClaimsModel, RewardBreakdown, TokenIdModel } from "./reward.model";
|
6
6
|
import { RewardRepository } from "./reward.repository";
|
7
7
|
export declare abstract class RewardService {
|
8
8
|
static hashId(root: string, recipient: string, rewardTokenId: string): string;
|
@@ -536,10 +536,6 @@ export declare abstract class RewardService {
|
|
536
536
|
rewards: Awaited<ReturnType<(typeof RewardService)["format"]>>;
|
537
537
|
}[]>;
|
538
538
|
static registerClaims(claims: RegisterClaimsModel): Promise<void>;
|
539
|
-
static updatePendings(data: UpdatePendingModel): Promise<{
|
540
|
-
created: number;
|
541
|
-
updated: number;
|
542
|
-
}>;
|
543
539
|
static countOnChain(chainId: number): Promise<{
|
544
540
|
[x: string]: {
|
545
541
|
rewardCount: number;
|
@@ -143,15 +143,17 @@ export class RewardService {
|
|
143
143
|
const claims = await DistributorService(chainId).claimedMultiple(user, rewards.map(reward => reward.RewardToken.address));
|
144
144
|
const rootsWithRewardOnChain = await RewardService.findManyRootsOnChain(chainId);
|
145
145
|
for (const [index, reward] of rewards.entries()) {
|
146
|
+
const tokenId = TokenService.hashId(reward.RewardToken);
|
146
147
|
const merklRootClaimedOn = claims[index].merkleRoot;
|
147
148
|
// -> claim is on the current root (chainData.merklRoot) -> claimed === accumulated
|
148
149
|
if (merklRootClaimedOn === roots.live) {
|
149
150
|
reward.claimed = reward.amount;
|
151
|
+
await RewardRepository.updateRewardClaimed(user, tokenId, reward.amount);
|
150
152
|
for (const breakdown of reward.Breakdown) {
|
151
153
|
if (BigInt(breakdown.claimed) === BigInt(breakdown.amount))
|
152
154
|
continue;
|
153
155
|
breakdown.claimed = breakdown.amount; // Set unclaim to 0
|
154
|
-
await RewardRepository.
|
156
|
+
await RewardRepository.updateBreakdownClaimed(user, tokenId, reward.Breakdown[0].campaignId, reward.Breakdown[0].reason, reward.Breakdown[0].amount);
|
155
157
|
}
|
156
158
|
}
|
157
159
|
// -> claim is on a tree we have in db -> claimed === accumulated of the rewards of lastTree
|
@@ -160,13 +162,14 @@ export class RewardService {
|
|
160
162
|
if (!lastTreeRewards)
|
161
163
|
continue;
|
162
164
|
reward.claimed = lastTreeRewards.amount;
|
165
|
+
await RewardRepository.updateRewardClaimed(user, tokenId, lastTreeRewards.amount);
|
163
166
|
for (const breakdown of reward.Breakdown) {
|
164
167
|
const lastTreeRewardsBreakdown = lastTreeRewards.Breakdown.find(lastTreeBreakdown => lastTreeBreakdown.reason === breakdown.reason &&
|
165
168
|
lastTreeBreakdown.Campaign.campaignId === breakdown.Campaign.campaignId);
|
166
169
|
if (!lastTreeRewardsBreakdown)
|
167
170
|
continue;
|
168
171
|
breakdown.claimed = lastTreeRewardsBreakdown.amount;
|
169
|
-
await RewardRepository.
|
172
|
+
await RewardRepository.updateBreakdownClaimed(user, tokenId, breakdown.campaignId, breakdown.reason, breakdown.amount);
|
170
173
|
}
|
171
174
|
}
|
172
175
|
}
|
@@ -233,60 +236,6 @@ export class RewardService {
|
|
233
236
|
}
|
234
237
|
}
|
235
238
|
}
|
236
|
-
static async updatePendings(data) {
|
237
|
-
const rewardTokenId = await TokenService.hashId({ address: data.rewardToken, chainId: data.distributionChainId });
|
238
|
-
const campaignId = await CampaignService.hashId({
|
239
|
-
distributionChain: data.distributionChainId,
|
240
|
-
campaignId: data.campaignId,
|
241
|
-
});
|
242
|
-
const rewardUniques = {};
|
243
|
-
// Adds a record to the Reward row where pendings need to be updated
|
244
|
-
const updateRewardUniques = (recipient, pending, previousPending) => {
|
245
|
-
const rewardId = RewardService.hashId(data.root, recipient, rewardTokenId);
|
246
|
-
if (!rewardUniques[rewardId]) {
|
247
|
-
rewardUniques[rewardId] = { pending: "0", recipient: recipient };
|
248
|
-
}
|
249
|
-
rewardUniques[rewardId].pending = (BigInt(rewardUniques[rewardId].pending) +
|
250
|
-
BigInt(pending) -
|
251
|
-
BigInt(previousPending ?? "0")) // Store the delta
|
252
|
-
.toString();
|
253
|
-
};
|
254
|
-
const breakdownUniques = await data.data.map(({ recipient, reason }) => {
|
255
|
-
const rewardId = RewardService.hashId(data.root, recipient, rewardTokenId);
|
256
|
-
return { rewardId, reason, campaignId };
|
257
|
-
});
|
258
|
-
const breakdownToUpdate = [];
|
259
|
-
const breakdownToCreate = [];
|
260
|
-
const breakdownExists = await RewardRepository.findManyBreakdownUniques(breakdownUniques);
|
261
|
-
for (const [pointIndex, point] of data.data.entries()) {
|
262
|
-
updateRewardUniques(point.recipient, point.pending, breakdownExists[pointIndex]?.pending);
|
263
|
-
if (!!breakdownExists[pointIndex]) {
|
264
|
-
breakdownToUpdate.push(point);
|
265
|
-
}
|
266
|
-
else {
|
267
|
-
breakdownToCreate.push(point);
|
268
|
-
}
|
269
|
-
}
|
270
|
-
const toUpdate = [];
|
271
|
-
const toCreate = [];
|
272
|
-
const exists = await RewardRepository.findManyRewardUniques(Object.keys(rewardUniques));
|
273
|
-
for (const [pointIndex, point] of Object.values(rewardUniques).entries()) {
|
274
|
-
if (!!exists[pointIndex]) {
|
275
|
-
toUpdate.push({
|
276
|
-
...point,
|
277
|
-
pending: (BigInt(exists[pointIndex].pending) + BigInt(point.pending)).toString(), // Store the delta
|
278
|
-
});
|
279
|
-
}
|
280
|
-
else {
|
281
|
-
toCreate.push(point);
|
282
|
-
}
|
283
|
-
}
|
284
|
-
await RewardRepository.updateRewardPendings(rewardTokenId, data.root, toUpdate);
|
285
|
-
await RewardRepository.createRewardPendings(rewardTokenId, data.root, toCreate);
|
286
|
-
await RewardRepository.updateBreakdownPendings(rewardTokenId, data.root, campaignId, breakdownToUpdate);
|
287
|
-
await RewardRepository.createBreakdownPendings(rewardTokenId, data.root, campaignId, breakdownToCreate);
|
288
|
-
return { created: breakdownToCreate.length, updated: breakdownToUpdate.length };
|
289
|
-
}
|
290
239
|
static async countOnChain(chainId) {
|
291
240
|
const roots = await MerklRootService.fetch(chainId);
|
292
241
|
const promises = [
|