@merkl/api 0.19.21 → 0.19.22

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.
@@ -188,6 +188,6 @@ export const tokenTypeToProtocol = {
188
188
  [tokenType.hanji_liquidity_vault_token]: { protocol: "Hanji", action: OpportunityAction.POOL },
189
189
  [tokenType.xU308]: { protocol: "Uranium", action: OpportunityAction.HOLD },
190
190
  [tokenType.bunniV2]: { protocol: "Bunni V2", action: OpportunityAction.HOLD },
191
- [tokenType.beratrax_vault]: { protocol: "BeraTrax", action: OpportunityAction.POOL },
192
- [tokenType.beraborrow_gauge]: { protocol: "Beraborrow", action: OpportunityAction.POOL },
191
+ [tokenType.beratrax_vault]: { protocol: "BeraTrax", action: OpportunityAction.HOLD },
192
+ [tokenType.beraborrow_gauge]: { protocol: "Beraborrow", action: OpportunityAction.HOLD },
193
193
  };
@@ -2,7 +2,7 @@ import type { Pricer } from "@/utils/pricer";
2
2
  import { type Campaign, type CampaignParameters } from "@sdk";
3
3
  import type { BigNumber } from "ethers";
4
4
  import { GenericProcessor, type dataType, type mandatoryCallKeys } from "../GenericProcessor";
5
- import { tokenType, type tokenTypeStruct } from "../helpers/tokenType";
5
+ import type { tokenType, tokenTypeStruct } from "../helpers/tokenType";
6
6
  type callType = {
7
7
  key: keyof dataRawBG;
8
8
  call: string;
@@ -3,7 +3,6 @@ import { createCall } from "@/utils/encodeCalls";
3
3
  import { generateCardName } from "@/utils/generateCardName";
4
4
  import { BN2Number } from "@sdk";
5
5
  import { GenericProcessor, Round } from "../GenericProcessor";
6
- import { tokenType } from "../helpers/tokenType";
7
6
  export class BEXRewardGaugeProcessor extends GenericProcessor {
8
7
  rounds = {
9
8
  round1: [{ key: "gyroscopeToken", call: "lp_token", target: "tokenAddress" }],
@@ -57,14 +56,13 @@ export class BEXRewardGaugeProcessor extends GenericProcessor {
57
56
  symbols.push(symbol);
58
57
  }
59
58
  let adjustedPoolTotalSupply = BN2Number(typeInfo.totalSupplyUnderlyingPoolTokens, 18);
60
- if (type === tokenType.beratrax_vault) {
61
- // Weird edge case where a lot of the supply is in a weird contract
62
- adjustedPoolTotalSupply -= BN2Number(typeInfo.poolHolderBalance, 18);
63
- }
64
- if (type === tokenType.beraborrow_gauge) {
65
- // Remove tokens in the vault from the total supply
66
- adjustedPoolTotalSupply -= BN2Number(typeInfo.vaultBalance, 18);
67
- }
59
+ // if (type === tokenType.beratrax_vault) {
60
+ // // Weird edge case where a lot of the supply is in a weird contract
61
+ // adjustedPoolTotalSupply -= BN2Number(typeInfo.poolHolderBalance, 18);
62
+ // }
63
+ // if (type === tokenType.beraborrow_gauge) {
64
+ // Remove tokens in the vault from the total supply
65
+ adjustedPoolTotalSupply -= BN2Number(typeInfo.vaultBalance, 18);
68
66
  let percentageOfSupplyUnderlyingPoolTokens = 1;
69
67
  if (adjustedPoolTotalSupply > 0) {
70
68
  percentageOfSupplyUnderlyingPoolTokens =
@@ -45,6 +45,11 @@ export class Erc20Metadata {
45
45
  tokens.push({ chainId: computeChainId, address: dynamicData.typeInfo.token0 });
46
46
  tokens.push({ chainId: computeChainId, address: dynamicData.typeInfo.token1 });
47
47
  }
48
+ // Case of quad vaults
49
+ if (!!dynamicData && !!dynamicData.typeInfo?.token2 && !!dynamicData.typeInfo?.token3) {
50
+ tokens.push({ chainId: computeChainId, address: dynamicData.typeInfo.token2 });
51
+ tokens.push({ chainId: computeChainId, address: dynamicData.typeInfo.token3 });
52
+ }
48
53
  // Case of tripools
49
54
  if (!!dynamicData &&
50
55
  !!dynamicData.typeInfo?.token0Address &&
@@ -121,9 +121,12 @@ export class OpportunityRepository {
121
121
  };
122
122
  }
123
123
  static async create(newOpp, upsert = false) {
124
- const opportunity = await apiDbClient.opportunity.findUnique({ where: { id: newOpp.id } });
125
- if (!!opportunity && !upsert) {
126
- return opportunity;
124
+ const previousOpportunity = await apiDbClient.opportunity.findUnique({
125
+ where: { id: newOpp.id },
126
+ include: { Tokens: true, Protocols: true },
127
+ });
128
+ if (!!previousOpportunity && !upsert) {
129
+ return previousOpportunity;
127
130
  }
128
131
  if (!!newOpp.mainProtocol) {
129
132
  let mainProtocol = await apiDbClient.protocol.findUnique({ where: { id: newOpp.mainProtocol } });
@@ -147,6 +150,25 @@ export class OpportunityRepository {
147
150
  if (mainProtocol.tags.includes("LENDING") && !!newOpp.name && newOpp.name.includes("Supply"))
148
151
  newOpp.action = "LEND";
149
152
  }
153
+ const toDisconnect = {
154
+ protocols: [],
155
+ tokens: [],
156
+ };
157
+ if (!!previousOpportunity) {
158
+ for (const protocol of previousOpportunity.Protocols) {
159
+ if (!newOpp.protocols || !newOpp.protocols.includes(protocol.id)) {
160
+ toDisconnect.protocols.push(protocol.id);
161
+ }
162
+ }
163
+ for (const token of previousOpportunity.Tokens) {
164
+ if (!newOpp.tokens.some(newToken => newToken.chainId === token.chainId && newToken.address === token.address)) {
165
+ toDisconnect.tokens.push({
166
+ chainId: token.chainId,
167
+ address: token.address,
168
+ });
169
+ }
170
+ }
171
+ }
150
172
  const data = {
151
173
  id: newOpp.id,
152
174
  action: newOpp.action ?? "HOLD",
@@ -172,11 +194,47 @@ export class OpportunityRepository {
172
194
  }),
173
195
  },
174
196
  };
197
+ const dataWithDisconnect = {
198
+ id: newOpp.id,
199
+ action: newOpp.action ?? "HOLD",
200
+ identifier: newOpp.identifier,
201
+ name: newOpp.name,
202
+ status: newOpp.status,
203
+ type: newOpp.type,
204
+ Chain: { connect: { id: newOpp.chainId } },
205
+ MainProtocol: !!newOpp.mainProtocol ? { connect: { id: newOpp.mainProtocol } } : undefined,
206
+ Protocols: {
207
+ connect: (newOpp.protocols ?? []).map((protocol) => {
208
+ return { id: protocol };
209
+ }),
210
+ disconnect: (toDisconnect.protocols ?? []).map((protocol) => {
211
+ return { id: protocol };
212
+ }),
213
+ },
214
+ Tokens: {
215
+ connect: newOpp.tokens.map((token) => {
216
+ return {
217
+ chainId_address: {
218
+ chainId: token.chainId,
219
+ address: token.address,
220
+ },
221
+ };
222
+ }),
223
+ disconnect: toDisconnect.tokens.map((token) => {
224
+ return {
225
+ chainId_address: {
226
+ chainId: token.chainId,
227
+ address: token.address,
228
+ },
229
+ };
230
+ }),
231
+ },
232
+ };
175
233
  if (upsert) {
176
234
  await apiDbClient.opportunity.upsert({
177
235
  where: { id: newOpp.id },
178
236
  create: data,
179
- update: data,
237
+ update: dataWithDisconnect,
180
238
  });
181
239
  }
182
240
  else {