@merkl/api 0.19.16 → 0.19.18

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.
@@ -16,6 +16,7 @@ type callKeysBG = mandatoryCallKeys & {
16
16
  poolId: string;
17
17
  vault: string;
18
18
  vaultBalance: string;
19
+ poolHolder: string;
19
20
  };
20
21
  type dataRawBG = callKeysBG & {
21
22
  poolTokensRaw: Array<string[] | BigNumber[]>;
@@ -23,6 +24,8 @@ type dataRawBG = callKeysBG & {
23
24
  token: string;
24
25
  balance: string;
25
26
  }>;
27
+ poolHolder: string;
28
+ poolHolderBalance: string;
26
29
  };
27
30
  type dataTypeBG = dataType & {
28
31
  gyroscopeToken: string;
@@ -36,6 +39,7 @@ type dataTypeBG = dataType & {
36
39
  balance: string;
37
40
  }>;
38
41
  vaultBalance: string;
42
+ poolHolderBalance: string;
39
43
  };
40
44
  export declare class BEXRewardGaugeProcessor extends GenericProcessor<callKeysBG, dataRawBG, dataTypeBG> {
41
45
  rounds: {
@@ -44,6 +48,7 @@ export declare class BEXRewardGaugeProcessor extends GenericProcessor<callKeysBG
44
48
  round3: callType[];
45
49
  round4: callType[];
46
50
  };
51
+ processingRound2(typeInfo: dataRawBG): void;
47
52
  processingRound4(typeInfo: dataRawBG): void;
48
53
  processingRound5(index: number, type: tokenType, typeInfo: dataRawBG, calls: string[], campaign: CampaignParameters<Campaign.ERC20> | CampaignParameters<Campaign.EULER>, pricer: Pricer): Promise<dataTypeBG>;
49
54
  computeRound4(index: number, type: tokenType, typeInfo: dataRawBG, calls: string[], campaign: CampaignParameters<Campaign.ERC20>): tokenTypeStruct;
@@ -12,6 +12,7 @@ export class BEXRewardGaugeProcessor extends GenericProcessor {
12
12
  { key: "totalSupplyUnderlyingPoolTokens", call: "totalSupply", target: "gyroscopeToken" },
13
13
  { key: "poolId", call: "getPoolId", target: "gyroscopeToken" },
14
14
  { key: "vault", call: "getVault", target: "gyroscopeToken" },
15
+ { key: "poolHolderBalance", call: "balanceOf", target: "gyroscopeToken", metaData: "poolHolder" },
15
16
  ],
16
17
  round3: [
17
18
  { key: "poolTokensRaw", call: "getPoolTokens", target: "vault", metaData: "poolId" },
@@ -20,6 +21,9 @@ export class BEXRewardGaugeProcessor extends GenericProcessor {
20
21
  round4: [{ key: "totalSupply", call: "totalSupply", target: "tokenAddress" }],
21
22
  };
22
23
  // override computeRound1(): void {}
24
+ processingRound2(typeInfo) {
25
+ typeInfo.poolHolder = "0xC2BaA8443cDA8EBE51a640905A8E6bc4e1f9872c";
26
+ }
23
27
  processingRound4(typeInfo) {
24
28
  const tokens = typeInfo.poolTokensRaw[0];
25
29
  const balances = typeInfo.poolTokensRaw[1];
@@ -52,10 +56,10 @@ export class BEXRewardGaugeProcessor extends GenericProcessor {
52
56
  tvlUnderlyingPool += poolTokensinfo[poolToken.token].price * poolTokensinfo[poolToken.token].amountInPool;
53
57
  symbols.push(symbol);
54
58
  }
55
- let adjustedPoolTotalSupply = BN2Number(typeInfo.totalSupplyUnderlyingPoolTokens, 18) - BN2Number(typeInfo.vaultBalance, 18);
59
+ let adjustedPoolTotalSupply = BN2Number(typeInfo.totalSupplyUnderlyingPoolTokens, 18); //- BN2Number(typeInfo.vaultBalance, 18);
56
60
  if (type === tokenType.beratrax_vault) {
57
61
  // Weird edge case where the total supply is 80k higher than it should be because they minted stuff on an EOA
58
- adjustedPoolTotalSupply -= 35724494.54 + 82793;
62
+ adjustedPoolTotalSupply -= BN2Number(typeInfo.poolHolderBalance, 18);
59
63
  }
60
64
  let percentageOfSupplyUnderlyingPoolTokens = 1;
61
65
  if (adjustedPoolTotalSupply > 0) {
@@ -65,6 +65,12 @@ export class ClammMetadata {
65
65
  }
66
66
  }
67
67
  }
68
+ // Protocol id normalization
69
+ let mainProtocol = AMM[params.amm]
70
+ ? camelToKebabCase(AMM[params.amm].replace(/\/?(V\d+)/g, "").replaceAll("Algebra", ""))
71
+ : undefined;
72
+ if (mainProtocol?.includes("stryke"))
73
+ mainProtocol = "stryke";
68
74
  return {
69
75
  name: `Provide liquidity to ${whitelistNameString} ${platform} ${params.symbolToken0}-${params.symbolToken1}${params.poolFee ? ` ${params.poolFee}%` : ""}`,
70
76
  action: OpportunityAction.POOL,
@@ -72,7 +78,7 @@ export class ClammMetadata {
72
78
  { chainId: computeChainId, address: params.token0 },
73
79
  { chainId: computeChainId, address: params.token1 },
74
80
  ],
75
- mainProtocol: AMM[params.amm] ? camelToKebabCase(AMM[params.amm]) : undefined,
81
+ mainProtocol,
76
82
  depositUrl: ClammMetadata.generateUrl(computeChainId, params),
77
83
  };
78
84
  }
@@ -121,6 +121,10 @@ 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;
127
+ }
124
128
  if (!!newOpp.mainProtocol) {
125
129
  let mainProtocol = await apiDbClient.protocol.findUnique({ where: { id: newOpp.mainProtocol } });
126
130
  if (!mainProtocol) {
@@ -176,10 +180,6 @@ export class OpportunityRepository {
176
180
  });
177
181
  }
178
182
  else {
179
- const opportunity = await apiDbClient.opportunity.findUnique({ where: { id: newOpp.id } });
180
- if (!!opportunity) {
181
- return opportunity;
182
- }
183
183
  await apiDbClient.opportunity.create({ data });
184
184
  }
185
185
  return await apiDbClient.opportunity.findUnique({ where: { id: newOpp.id } });
@@ -9,6 +9,7 @@ export declare abstract class ProtocolRepository {
9
9
  tags: string[];
10
10
  icon: string;
11
11
  }>;
12
+ static changeId(oldId: string, newId: string): Promise<void>;
12
13
  static read(type: string): Promise<{
13
14
  id: string;
14
15
  name: string;
@@ -1,3 +1,4 @@
1
+ import { log } from "@/utils/logger";
1
2
  import { apiDbClient } from "@db";
2
3
  // ─── Protocols Repository ────────────────────────────────────────────────────
3
4
  export class ProtocolRepository {
@@ -13,6 +14,65 @@ export class ProtocolRepository {
13
14
  },
14
15
  });
15
16
  }
17
+ static async changeId(oldId, newId) {
18
+ await apiDbClient.opportunity.updateMany({
19
+ where: {
20
+ mainProtocolId: oldId,
21
+ },
22
+ data: {
23
+ mainProtocolId: newId,
24
+ },
25
+ });
26
+ await apiDbClient.rewardBreakdown.updateMany({
27
+ where: {
28
+ protocolId: oldId,
29
+ },
30
+ data: {
31
+ protocolId: newId,
32
+ },
33
+ });
34
+ const opportunities = await apiDbClient.opportunity.findMany({
35
+ where: {
36
+ Protocols: {
37
+ some: {
38
+ id: oldId,
39
+ },
40
+ },
41
+ },
42
+ });
43
+ for (const opportunity of opportunities) {
44
+ await apiDbClient.opportunity.update({
45
+ where: {
46
+ id: opportunity.id,
47
+ },
48
+ data: {
49
+ Protocols: {
50
+ disconnect: [
51
+ {
52
+ id: oldId,
53
+ },
54
+ ],
55
+ connect: [
56
+ {
57
+ id: newId,
58
+ },
59
+ ],
60
+ },
61
+ },
62
+ });
63
+ }
64
+ try {
65
+ await apiDbClient.protocol.delete({
66
+ where: {
67
+ id: oldId,
68
+ },
69
+ });
70
+ log.info(`protocol with id ${oldId} deleted`);
71
+ }
72
+ catch {
73
+ log.warn(`protocol with id ${oldId} not found`);
74
+ }
75
+ }
16
76
  static async read(type) {
17
77
  return await apiDbClient.protocol.findUnique({ where: { id: type } });
18
78
  }