@merkl/api 0.10.152 → 0.10.154
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/src/eden/index.d.ts +53 -34
- package/dist/src/index.d.ts +17 -12
- package/dist/src/libs/campaigns/campaignTypes/ERC20SubTypes/helpers/tokenType.d.ts +2 -1
- package/dist/src/libs/campaigns/campaignTypes/ERC20SubTypes/helpers/tokenType.js +4 -0
- package/dist/src/libs/campaigns/campaignTypes/ERC20SubTypes/processor/MaverickBPProcessor.js +0 -1
- package/dist/src/libs/campaigns/campaignTypes/ERC20SubTypes/processor/ZkSwapThreePoolProcessor.d.ts +53 -0
- package/dist/src/libs/campaigns/campaignTypes/ERC20SubTypes/processor/ZkSwapThreePoolProcessor.js +55 -0
- package/dist/src/libs/campaigns/campaignTypes/ERC20SubTypes/processor/processorMapping.js +2 -0
- package/dist/src/libs/campaigns/campaignTypes/ERC20SubTypes/subtypesRound1RefactoFinal.js +6 -1
- package/dist/src/libs/campaigns/utils/getLastEligibilityRatio.js +15 -6
- package/dist/src/modules/v4/campaign/campaign.controller.d.ts +14 -12
- package/dist/src/modules/v4/campaign/campaign.controller.js +1 -1
- package/dist/src/modules/v4/chainInteraction/chainInteraction.service.d.ts +2 -0
- package/dist/src/modules/v4/chainInteraction/chainInteraction.service.js +4 -0
- package/dist/src/modules/v4/chainInteraction/index.d.ts +1 -0
- package/dist/src/modules/v4/chainInteraction/index.js +1 -0
- package/dist/src/modules/v4/opportunity/opportunity.controller.d.ts +3 -0
- package/dist/src/modules/v4/opportunity/opportunity.model.d.ts +2 -1
- package/dist/src/modules/v4/opportunity/opportunity.model.js +2 -1
- package/dist/src/modules/v4/opportunity/opportunity.repository.js +1 -0
- package/dist/src/modules/v4/router.d.ts +17 -12
- package/dist/src/modules/v4/tracer/index.d.ts +1 -0
- package/dist/src/modules/v4/tracer/index.js +1 -0
- package/dist/src/modules/v4/tracer/tracer.service.d.ts +3 -0
- package/dist/src/modules/v4/tracer/tracer.service.js +30 -0
- package/dist/src/routes/v3/ERC20Campaigns.d.ts +17 -12
- package/dist/src/routes/v3/blacklist.d.ts +17 -12
- package/dist/src/routes/v3/campaigns.d.ts +17 -12
- package/dist/src/routes/v3/campaignsInfo.d.ts +17 -12
- package/dist/src/routes/v3/multiChainPositions.d.ts +17 -12
- package/dist/src/routes/v3/opportunity.d.ts +17 -12
- package/dist/src/routes/v3/positions.d.ts +17 -12
- package/dist/src/routes/v3/rewards.d.ts +17 -12
- package/dist/src/routes/v3/updates.d.ts +17 -12
- package/dist/src/routes/v3/userRewards.d.ts +17 -12
- package/dist/src/utils/decodeCalls.js +7 -1
- package/dist/src/utils/encodeCalls.js +19 -1
- package/dist/src/utils/generateCardName.js +3 -1
- package/dist/tsconfig.package.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/dist/src/libs/rewards/userRewards.d.ts +0 -2
- package/dist/src/libs/rewards/userRewards.js +0 -154
package/package.json
CHANGED
@@ -1,154 +0,0 @@
|
|
1
|
-
import { engineDbClient } from "../../utils/prisma";
|
2
|
-
import { DistributorInterface, NETWORK_LABELS, registry } from "@sdk";
|
3
|
-
import Big from "big.js";
|
4
|
-
import { BigNumber } from "ethers";
|
5
|
-
import { batchMulticallCallWithRetry } from "../../utils/generic";
|
6
|
-
export async function getUserRewards(merklChainId, merklRoot, user, mainParameter, rewardToken, proof) {
|
7
|
-
if (!merklRoot)
|
8
|
-
throw new Error(`No merklRoot when calling getUserRewards on ${NETWORK_LABELS[merklChainId]} for ${user}`);
|
9
|
-
const res = {};
|
10
|
-
let filters = {
|
11
|
-
chainId: merklChainId,
|
12
|
-
recipient: user,
|
13
|
-
};
|
14
|
-
if (rewardToken) {
|
15
|
-
filters = {
|
16
|
-
...filters,
|
17
|
-
rewardToken: rewardToken,
|
18
|
-
};
|
19
|
-
}
|
20
|
-
const [leaves, claims] = await engineDbClient.$transaction([
|
21
|
-
engineDbClient.leaves.findMany({ where: { ...filters, root: merklRoot } }),
|
22
|
-
engineDbClient.claims.findMany({ where: { ...filters } }),
|
23
|
-
]);
|
24
|
-
const calls = [];
|
25
|
-
const earnedTokens = [];
|
26
|
-
const claimedTokenAmounts = {};
|
27
|
-
for (const leaf of leaves) {
|
28
|
-
if (!earnedTokens.includes(leaf.rewardToken)) {
|
29
|
-
earnedTokens.push(leaf.rewardToken);
|
30
|
-
}
|
31
|
-
}
|
32
|
-
for (const token of earnedTokens) {
|
33
|
-
calls.push({
|
34
|
-
target: registry(merklChainId)?.Merkl?.Distributor,
|
35
|
-
callData: DistributorInterface.encodeFunctionData("claimed", [user, token]),
|
36
|
-
allowFailure: true,
|
37
|
-
});
|
38
|
-
}
|
39
|
-
const claimedCallResult = await batchMulticallCallWithRetry(merklChainId, { calls });
|
40
|
-
const fullyClaimedTokens = [];
|
41
|
-
for (const [index, token] of earnedTokens.entries()) {
|
42
|
-
const amount = DistributorInterface.decodeFunctionResult("claimed", claimedCallResult[index].returnData)[0];
|
43
|
-
const root = DistributorInterface.decodeFunctionResult("claimed", claimedCallResult[index].returnData)[2];
|
44
|
-
claimedTokenAmounts[token] = amount;
|
45
|
-
if (root === merklRoot) {
|
46
|
-
fullyClaimedTokens.push(token);
|
47
|
-
}
|
48
|
-
}
|
49
|
-
let campaignFilters = {
|
50
|
-
campaignId: { in: leaves.map(leaf => leaf.campaignId) },
|
51
|
-
chainId: merklChainId,
|
52
|
-
};
|
53
|
-
if (mainParameter) {
|
54
|
-
campaignFilters = {
|
55
|
-
...campaignFilters,
|
56
|
-
mainParameter: mainParameter,
|
57
|
-
};
|
58
|
-
}
|
59
|
-
if (rewardToken) {
|
60
|
-
campaignFilters = {
|
61
|
-
...campaignFilters,
|
62
|
-
rewardToken: rewardToken,
|
63
|
-
};
|
64
|
-
}
|
65
|
-
const campaigns = await engineDbClient.campaigns.findMany({ where: campaignFilters });
|
66
|
-
const campaignMapping = campaigns.reduce((prev, campaign) => {
|
67
|
-
prev[`${campaign.chainId}_${campaign.campaignId}`] = campaign;
|
68
|
-
return prev;
|
69
|
-
}, {});
|
70
|
-
if (leaves.length === 0) {
|
71
|
-
return {};
|
72
|
-
}
|
73
|
-
const proofMapping = {};
|
74
|
-
if (proof) {
|
75
|
-
const proofs = await engineDbClient.proofs.findMany({
|
76
|
-
select: {
|
77
|
-
chainId: true,
|
78
|
-
proof: true,
|
79
|
-
rewardToken: true,
|
80
|
-
},
|
81
|
-
where: {
|
82
|
-
chainId: merklChainId,
|
83
|
-
recipient: user,
|
84
|
-
root: merklRoot,
|
85
|
-
},
|
86
|
-
});
|
87
|
-
// Create a map of proofs for each token
|
88
|
-
for (const proof of proofs) {
|
89
|
-
if (!Object.hasOwn(proofMapping, proof.chainId)) {
|
90
|
-
proofMapping[proof.chainId] = {};
|
91
|
-
}
|
92
|
-
proofMapping[proof.chainId][proof.rewardToken] = proof.proof;
|
93
|
-
}
|
94
|
-
}
|
95
|
-
for (const leaf of leaves) {
|
96
|
-
if (mainParameter && campaignMapping[`${leaf.chainId}_${leaf.campaignId}`]?.mainParameter !== mainParameter) {
|
97
|
-
continue;
|
98
|
-
}
|
99
|
-
if (!Object.hasOwn(res, leaf.rewardToken)) {
|
100
|
-
res[leaf.rewardToken] = {
|
101
|
-
accumulated: leaf.amount,
|
102
|
-
decimals: campaignMapping?.[`${leaf.chainId}_${leaf.campaignId}`]?.campaignParameters
|
103
|
-
?.decimalsRewardToken,
|
104
|
-
reasons: {},
|
105
|
-
symbol: campaignMapping?.[`${leaf.chainId}_${leaf.campaignId}`]?.campaignParameters?.symbolRewardToken,
|
106
|
-
unclaimed: fullyClaimedTokens.includes(leaf.rewardToken) ? "0" : leaf.amount,
|
107
|
-
};
|
108
|
-
if (proof) {
|
109
|
-
res[leaf.rewardToken].proof = proofMapping?.[leaf.chainId]?.[leaf.rewardToken] ?? [];
|
110
|
-
}
|
111
|
-
}
|
112
|
-
else {
|
113
|
-
res[leaf.rewardToken].accumulated = new Big(leaf.amount)
|
114
|
-
.add(new Big(res[leaf.rewardToken].accumulated))
|
115
|
-
.toFixed(0);
|
116
|
-
res[leaf.rewardToken].unclaimed = fullyClaimedTokens.includes(leaf.rewardToken)
|
117
|
-
? "0"
|
118
|
-
: new Big(leaf.amount).add(new Big(res[leaf.rewardToken].unclaimed)).toFixed(0);
|
119
|
-
}
|
120
|
-
if (!Object.hasOwn(res[leaf.rewardToken].reasons, leaf.reason)) {
|
121
|
-
res[leaf.rewardToken].reasons[leaf.reason] = {
|
122
|
-
accumulated: leaf.amount,
|
123
|
-
unclaimed: fullyClaimedTokens.includes(leaf.rewardToken) ? "0" : leaf.amount,
|
124
|
-
};
|
125
|
-
}
|
126
|
-
else {
|
127
|
-
res[leaf.rewardToken].reasons[leaf.reason].accumulated = new Big(leaf.amount)
|
128
|
-
.add(new Big(res[leaf.rewardToken].reasons[leaf.reason].accumulated))
|
129
|
-
.toFixed(0);
|
130
|
-
res[leaf.rewardToken].reasons[leaf.reason].unclaimed = fullyClaimedTokens.includes(leaf.rewardToken)
|
131
|
-
? "0"
|
132
|
-
: new Big(leaf.amount).add(new Big(res[leaf.rewardToken].reasons[leaf.reason].unclaimed)).toFixed(0);
|
133
|
-
}
|
134
|
-
}
|
135
|
-
for (const claim of claims) {
|
136
|
-
if (mainParameter && campaignMapping[`${claim.chainId}_${claim.campaignId}`]?.mainParameter !== mainParameter) {
|
137
|
-
continue;
|
138
|
-
}
|
139
|
-
if (!!res?.[claim.rewardToken] && !fullyClaimedTokens.includes(claim.rewardToken)) {
|
140
|
-
res[claim.rewardToken].unclaimed = new Big(res[claim.rewardToken].unclaimed).sub(claim.claimed).toFixed(0);
|
141
|
-
if (!!res[claim.rewardToken].reasons?.[claim.reason]) {
|
142
|
-
res[claim.rewardToken].reasons[claim.reason].unclaimed = new Big(res[claim.rewardToken].reasons[claim.reason].unclaimed)
|
143
|
-
.sub(claim.claimed)
|
144
|
-
.toFixed(0);
|
145
|
-
}
|
146
|
-
}
|
147
|
-
}
|
148
|
-
for (const token of Object.keys(res)) {
|
149
|
-
if (BigNumber.from(res[token].accumulated).lte(claimedTokenAmounts?.[token] ?? "0") && !mainParameter) {
|
150
|
-
res[token].unclaimed = "0";
|
151
|
-
}
|
152
|
-
}
|
153
|
-
return res;
|
154
|
-
}
|