@merkl/api 0.13.15 → 0.14.0

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.
Files changed (31) hide show
  1. package/dist/src/jobs/etl/pendings.js +3 -1
  2. package/dist/src/jobs/etl/reward-breakdowns.js +3 -1
  3. package/dist/src/jobs/etl/rewards.js +3 -1
  4. package/dist/src/libs/campaigns/campaignTypes/ERC20DynamicData.d.ts +2 -1
  5. package/dist/src/libs/campaigns/campaignTypes/ERC20DynamicData.js +1 -1
  6. package/dist/src/libs/campaigns/campaignTypes/ERC20SubTypes/processor/EulerBorrowProcessor.d.ts +8 -12
  7. package/dist/src/libs/campaigns/campaignTypes/ERC20SubTypes/processor/EulerBorrowProcessor.js +28 -24
  8. package/dist/src/libs/campaigns/campaignTypes/ERC20SubTypes/processor/EulerLendProcessor.d.ts +7 -11
  9. package/dist/src/libs/campaigns/campaignTypes/ERC20SubTypes/processor/EulerLendProcessor.js +20 -21
  10. package/dist/src/libs/campaigns/campaignTypes/ERC20SubTypes/processor/GenericProcessor.d.ts +6 -5
  11. package/dist/src/libs/campaigns/campaignTypes/ERC20SubTypes/processor/GenericProcessor.js +4 -4
  12. package/dist/src/libs/campaigns/campaignTypes/ERC20SubTypes/processor/MaverickBPProcessor.d.ts +1 -1
  13. package/dist/src/libs/campaigns/campaignTypes/ERC20SubTypes/processor/MaverickBPProcessor.js +1 -1
  14. package/dist/src/libs/campaigns/campaignTypes/ERC20SubTypes/processor/NoLinkVaultProcessor.d.ts +1 -1
  15. package/dist/src/libs/campaigns/campaignTypes/ERC20SubTypes/processor/NoLinkVaultProcessor.js +2 -2
  16. package/dist/src/libs/campaigns/campaignTypes/ERC20SubTypes/processor/RfxProcessor.d.ts +1 -1
  17. package/dist/src/libs/campaigns/campaignTypes/ERC20SubTypes/processor/RfxProcessor.js +1 -1
  18. package/dist/src/libs/campaigns/campaignTypes/ERC20SubTypes/subtypesRound2.d.ts +3 -2
  19. package/dist/src/libs/campaigns/campaignTypes/ERC20SubTypes/subtypesRound2.js +2 -2
  20. package/dist/src/libs/campaigns/campaignsDynamicData.js +1 -2
  21. package/dist/src/modules/v4/bucket/bucket.model.d.ts +10 -0
  22. package/dist/src/modules/v4/bucket/bucket.model.js +85 -0
  23. package/dist/src/modules/v4/bucket/bucket.service.d.ts +8 -6
  24. package/dist/src/modules/v4/bucket/bucket.service.js +145 -83
  25. package/dist/src/modules/v4/campaign/campaign.repository.js +1 -2
  26. package/dist/src/modules/v4/programPayload/programPayload.repository.d.ts +4 -0
  27. package/dist/src/modules/v4/programPayload/programPayload.repository.js +61 -1
  28. package/dist/tsconfig.package.tsbuildinfo +1 -1
  29. package/package.json +1 -1
  30. package/dist/src/libs/campaigns/campaignTypes/EulerDynamicData.d.ts +0 -3
  31. package/dist/src/libs/campaigns/campaignTypes/EulerDynamicData.js +0 -165
@@ -1,97 +1,159 @@
1
- import { log } from "../../../utils/logger";
2
1
  import { Storage } from "@google-cloud/storage";
2
+ import { S3Client, gzipSync } from "bun";
3
+ // ─── BucketService Class ─────────────────────────────────────────────────────
3
4
  export class BucketService {
4
- // ─── Upload A File ───────────────────────────────────────────────────
5
- static async upload(bucketName, filename, data, isPublic) {
6
- const storage = new Storage({ projectId: "angle-production-1" });
7
- const file = await storage.bucket(bucketName).file(filename);
8
- await file.save(data);
9
- if (isPublic)
10
- await file.makePublic();
11
- return `https://storage.googleapis.com/${bucketName}/${filename}`;
5
+ // ─── Private Properties ──────────────────────────────────────────────
6
+ #s3Client;
7
+ #gcsBucket;
8
+ #encoder;
9
+ #decoder;
10
+ // ─── Default Options ─────────────────────────────────────────────────────────
11
+ defaultUploadOptions = {
12
+ type: "text/plain",
13
+ compression: true,
14
+ overwrite: true,
15
+ isPublic: false,
16
+ transform: obj => `${JSON.stringify(obj)}`,
17
+ separator: "\n",
18
+ };
19
+ // ─── Constructor ─────────────────────────────────────────────────────
20
+ constructor(bucket) {
21
+ this.#s3Client = new S3Client({
22
+ accessKeyId: process.env.GCS_ACCESS_ID,
23
+ secretAccessKey: process.env.GCS_SECRET,
24
+ endpoint: process.env.GCS_ENDPOINT,
25
+ bucket,
26
+ });
27
+ this.#gcsBucket = new Storage().bucket(bucket);
28
+ this.#encoder = new TextEncoder();
29
+ this.#decoder = new TextDecoder();
12
30
  }
13
- // ─── Write An Object As A Stream ─────────────────────────────────────
14
- static async writeStreamToBucket(data, fileName, bucketName, projectID, hook = JSON.stringify, isPublic = false, withLog = true) {
15
- const storage = new Storage({ projectId: projectID });
16
- const bucket = storage.bucket(bucketName);
17
- const file = bucket.file(fileName);
18
- const [exist] = await file.exists();
19
- if (exist) {
31
+ // ─── Process And Upload Chunks Of Data ───────────────────────────────
32
+ async pushArray(filename, arr, options) {
33
+ // const start = performance.now();
34
+ // ─── Initialization ──────────────────────────────────────────
35
+ options = { ...this.defaultUploadOptions, ...options };
36
+ const file = this.#s3Client.file(filename);
37
+ const writer = file.writer({
38
+ retry: 2,
39
+ queueSize: 10,
40
+ partSize: 5 * 1024 * 1024,
41
+ type: options.type,
42
+ });
43
+ // ─── Objects Array To Uint8Array ─────────────────────────────
44
+ const sink = new Bun.ArrayBufferSink();
45
+ sink.start({
46
+ asUint8Array: true,
47
+ });
48
+ for (let i = 0; i < arr.length; i++)
49
+ sink.write(this.#encoder.encode(`${options.transform(arr[i])}${options.separator}`));
50
+ let data = sink.end();
51
+ if (options.compression)
52
+ data = gzipSync(data);
53
+ // ─── ReadableStream Initialization From Blob ─────────────────
54
+ const blob = new Blob([data]);
55
+ const stream = blob.stream(50 * 1024 * 1024);
56
+ const reader = stream.getReader();
57
+ // ─── Start Writing Data To Bucket ────────────────────────────
58
+ if (options.overwrite && (await file.exists()))
20
59
  await file.delete();
60
+ let bytes = 0;
61
+ try {
62
+ while (true) {
63
+ const { done, value } = await reader.read();
64
+ if (done)
65
+ break;
66
+ bytes += await writer.write(value);
67
+ }
68
+ await writer.end();
21
69
  }
22
- await file.save("", { resumable: false });
23
- await file.setMetadata({
24
- cacheControl: "public, max-age=300",
25
- });
26
- if (isPublic) {
27
- await file.makePublic();
70
+ finally {
71
+ reader.releaseLock();
28
72
  }
29
- const writeStream = file.createWriteStream({
30
- resumable: false,
31
- gzip: true, // Enable gzip compression
32
- });
33
- const streamPromise = new Promise((resolve, reject) => {
34
- writeStream.on("error", reject);
35
- writeStream.on("finish", resolve);
73
+ // ─── Setting Proper Metadata ─────────────────────────────────
74
+ if (options.compression)
75
+ await this.#gcsBucket.file(filename).setMetadata({ contentEncoding: "gzip" });
76
+ if (options.isPublic)
77
+ await this.#gcsBucket.makePublic();
78
+ // ─── Return The Number Of Bytes Written ──────────────────────
79
+ return bytes;
80
+ }
81
+ // ─── Upload Data To Bucket ───────────────────────────────────────────
82
+ async push(filename, text, options) {
83
+ // const start = performance.now();
84
+ // ─── Initialization ──────────────────────────────────────────
85
+ options = { ...this.defaultUploadOptions, ...options };
86
+ const file = this.#s3Client.file(filename);
87
+ const data = options.compression ? gzipSync(this.#encoder.encode(text)) : this.#encoder.encode(text);
88
+ const writer = file.writer({
89
+ retry: 2,
90
+ queueSize: 10,
91
+ partSize: 5 * 1024 * 1024,
92
+ type: options.type,
36
93
  });
37
- for (const d of data) {
38
- await writeStream.write(`${hook(d)}\n`);
94
+ const blob = new Blob([data]);
95
+ const stream = blob.stream(50 * 1024 * 1024);
96
+ const reader = stream.getReader();
97
+ if (options.overwrite && (await file.exists()))
98
+ await file.delete();
99
+ // ─── Start Writing Data To Bucket ────────────────────────────
100
+ let bytes = 0;
101
+ try {
102
+ while (true) {
103
+ const { done, value } = await reader.read();
104
+ if (done)
105
+ break;
106
+ bytes += await writer.write(value);
107
+ }
108
+ await writer.end();
39
109
  }
40
- await writeStream.end();
41
- await streamPromise;
42
- withLog && log.local(`✅ successfully updated https://storage.cloud.google.com/${bucketName}/${fileName}`);
43
- }
44
- // ─── Read An Object As A Stream ──────────────────────────────────────
45
- static async readStreamFromBucket(fileName, bucketName, projectID, hook = line => JSON.parse(line), withLog = true) {
46
- const storage = new Storage({ projectId: projectID });
47
- const bucket = storage.bucket(bucketName);
48
- const file = bucket.file(fileName);
49
- const [exists] = await file.exists();
50
- if (!exists) {
51
- throw new Error(`File ${fileName} does not exist in bucket ${bucketName}`);
110
+ finally {
111
+ reader.releaseLock();
52
112
  }
53
- return new Promise((resolve, reject) => {
54
- const data = [];
55
- let buffer = "";
56
- file
57
- .createReadStream({
58
- decompress: true,
59
- })
60
- .on("data", async (chunk) => {
61
- // instead of using callback functions here, we could use pipe streams
62
- buffer += chunk.toString();
63
- const lines = buffer.split("\n");
64
- buffer = lines.pop() || "";
65
- for (const line of lines) {
66
- if (line.trim()) {
67
- const res = hook(line);
68
- data.push(res);
69
- }
113
+ // ─── Setting Proper Metadata ─────────────────────────────────
114
+ if (options.compression)
115
+ await this.#gcsBucket.file(filename).setMetadata({ contentEncoding: "gzip" });
116
+ if (options.isPublic)
117
+ await this.#gcsBucket.makePublic();
118
+ // ─── Return The Number Of Bytes Written ──────────────────────
119
+ return bytes;
120
+ }
121
+ // ─── Download And Process Chunks Of Data ─────────────────────────────
122
+ async pullArray(filename, callback, separator = "\n") {
123
+ const file = this.#s3Client.file(filename);
124
+ if (!(await file.exists))
125
+ throw new Error("File does not exists.");
126
+ const stream = file.stream();
127
+ const data = [];
128
+ let buffer = "";
129
+ for await (const chunk of stream) {
130
+ buffer += this.#decoder.decode(chunk);
131
+ const lines = buffer.split(separator);
132
+ buffer = lines.pop() || "";
133
+ for (const line of lines) {
134
+ try {
135
+ data.push(callback(line));
70
136
  }
71
- })
72
- .on("error", reject)
73
- .on("end", async () => {
74
- if (buffer.trim()) {
75
- const res = hook(buffer);
76
- data.push(res);
137
+ catch (err) {
138
+ if (err instanceof Error && err.message === "JSON Parse error: Unexpected EOF")
139
+ break;
77
140
  }
78
- withLog &&
79
- log.local(`✅ Successfully read ${data.length} items from https://storage.cloud.google.com/${bucketName}/${fileName}`);
80
- resolve(data);
81
- });
82
- });
83
- }
84
- // ─── Delete A File ───────────────────────────────────────────────────
85
- static async deleteFile(fileName, bucketName, projectID) {
86
- const storage = new Storage({ projectId: projectID });
87
- const bucket = storage.bucket(bucketName);
88
- const file = bucket.file(fileName);
89
- await file.delete();
141
+ }
142
+ }
143
+ if (buffer.trim())
144
+ data.push(callback(buffer));
145
+ return data;
90
146
  }
91
- // ─── Check If A File Exists ──────────────────────────────────────────
92
- static async exists(fileName, bucketName, projectID) {
93
- const storage = new Storage({ projectId: projectID });
94
- const [exists] = await storage.bucket(bucketName).file(fileName).exists();
95
- return exists;
147
+ // ─── Download Data From Bucket ───────────────────────────────────────
148
+ async pull(filename) {
149
+ const file = this.#s3Client.file(filename);
150
+ if (!(await file.exists))
151
+ throw new Error("File does not exists.");
152
+ const stream = file.stream();
153
+ let buffer = "";
154
+ for await (const chunk of stream)
155
+ buffer += this.#decoder.decode(chunk);
156
+ buffer = buffer.trim();
157
+ return buffer;
96
158
  }
97
159
  }
@@ -3,7 +3,7 @@ import { log } from "../../../utils/logger";
3
3
  import { apiDbClient, engineDbClient } from "../../../utils/prisma";
4
4
  import { ALL_CAMPAIGNS_FOR_CHAIN_AFTER } from "../../../utils/queries/allCampaigns";
5
5
  import { Prisma, RunStatus } from "../../../../database/api/.generated";
6
- import { MAX_COMPUTE_JOB_TIME, WEEK } from "@sdk";
6
+ import { MAX_COMPUTE_JOB_TIME } from "@sdk";
7
7
  import moment from "moment";
8
8
  import { OpportunityService } from "../opportunity";
9
9
  import { TokenService } from "../token";
@@ -235,7 +235,6 @@ export class CampaignRepository {
235
235
  where: {
236
236
  distributionChainId,
237
237
  startTimestamp: { lte: currentTime }, // The campaign has started
238
- endTimestamp: { gte: currentTime - WEEK }, // The campaign ended less than a week ago
239
238
  params: {
240
239
  path: ["shouldIgnore"],
241
240
  equals: Prisma.AnyNull,
@@ -251,6 +251,10 @@ export declare enum modeCampaigns {
251
251
  Kim_V4_WETH_MODE_Mode = "Kim V4 WETH/Mode 0x8cfE2A02dfBAbC56aE7e573170E35f88A38BeA55",
252
252
  Kim_Steer_CRS_V2_KIM_MODE_Mode = "Kim Steer CRS V2 Kim/Mode 0x86D9d9dd7A2c3146c6FAd51646F210Cb2E5FC12F",
253
253
  Kim_Steer_CRS_V2_and_EES_V2_WETH_USDT = "Kim Steer CRS V2 & EES V2 WETH/USDT 0xD8Abc2be7AD5D17940112969973357a3a3562998",
254
+ Kim_Ichi_SSD_Mode_Kim = "Kim Ichi SSD Mode/Kim 0x86d9d9dd7a2c3146c6fad51646f210cb2e5fc12f",
255
+ Kim_Steer_SSS_V2_weETH_ETH = "Kim Steer SSS V2 weETH/ETH 0xe24c8feb38ca2b18b542994bfba7e70880171035",
256
+ Kim_Ichi_SSD_wMLT_Mode = "Kim Ichi SSD wMLT/Mode 0xa186548320bdb79c714719e107ad5753ecb452d4",
257
+ Kim_Steer_CRS_V2_ezETH_ETH = "Kim Steer CRS V2 ezETH/ETH 0xd9a06f63e523757973ffd1a4606a1260252636d2",
254
258
  Ironclad_Borrow_uniBTC_Mode = "Ironclad Borrow uniBTC 0x80215c38DCb6ae91520F8251A077c124e7259688",
255
259
  Bedrock_Ionic_Supply_ionuniBTC_Mode = "Bedrock Ionic Supply uniBTC 0xa48750877a83f7dec11f722178c317b54a44d142",
256
260
  Bedrock_Ironclad_Supply_uniBTC_Mode = "Bedrock Ironclad Supply uniBTC 0x0F041cf2ae959f39215EFfB50d681Df55D4d90B1"
@@ -256,6 +256,10 @@ export var modeCampaigns;
256
256
  modeCampaigns["Kim_V4_WETH_MODE_Mode"] = "Kim V4 WETH/Mode 0x8cfE2A02dfBAbC56aE7e573170E35f88A38BeA55";
257
257
  modeCampaigns["Kim_Steer_CRS_V2_KIM_MODE_Mode"] = "Kim Steer CRS V2 Kim/Mode 0x86D9d9dd7A2c3146c6FAd51646F210Cb2E5FC12F";
258
258
  modeCampaigns["Kim_Steer_CRS_V2_and_EES_V2_WETH_USDT"] = "Kim Steer CRS V2 & EES V2 WETH/USDT 0xD8Abc2be7AD5D17940112969973357a3a3562998";
259
+ modeCampaigns["Kim_Ichi_SSD_Mode_Kim"] = "Kim Ichi SSD Mode/Kim 0x86d9d9dd7a2c3146c6fad51646f210cb2e5fc12f";
260
+ modeCampaigns["Kim_Steer_SSS_V2_weETH_ETH"] = "Kim Steer SSS V2 weETH/ETH 0xe24c8feb38ca2b18b542994bfba7e70880171035";
261
+ modeCampaigns["Kim_Ichi_SSD_wMLT_Mode"] = "Kim Ichi SSD wMLT/Mode 0xa186548320bdb79c714719e107ad5753ecb452d4";
262
+ modeCampaigns["Kim_Steer_CRS_V2_ezETH_ETH"] = "Kim Steer CRS V2 ezETH/ETH 0xd9a06f63e523757973ffd1a4606a1260252636d2";
259
263
  modeCampaigns["Ironclad_Borrow_uniBTC_Mode"] = "Ironclad Borrow uniBTC 0x80215c38DCb6ae91520F8251A077c124e7259688";
260
264
  modeCampaigns["Bedrock_Ionic_Supply_ionuniBTC_Mode"] = "Bedrock Ionic Supply uniBTC 0xa48750877a83f7dec11f722178c317b54a44d142";
261
265
  modeCampaigns["Bedrock_Ironclad_Supply_uniBTC_Mode"] = "Bedrock Ironclad Supply uniBTC 0x0F041cf2ae959f39215EFfB50d681Df55D4d90B1";
@@ -1581,7 +1585,7 @@ const ModeInterfaceCampaigns = {
1581
1585
  campaignType: Campaign.CLAMM,
1582
1586
  computeChainId: ChainId.MODE,
1583
1587
  hooks: [],
1584
- poolAddress: "0x879F9998c68cdaF28e4808fCc2b4f174c3CC5D97",
1588
+ poolAddress: "0xd8abc2be7ad5d17940112969973357a3a3562998",
1585
1589
  whitelist: ["0x879F9998c68cdaF28e4808fCc2b4f174c3CC5D97", "0x908731366f82668dDd3aE3B2498ADF52604E892d"],
1586
1590
  blacklist: [],
1587
1591
  url: "https://app.kim.exchange/liquidity/wizard?token0=0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee&token1=0xf0f161fda2712db8b566946122a5af183995e2ed",
@@ -1591,6 +1595,20 @@ const ModeInterfaceCampaigns = {
1591
1595
  weightToken0: 4000,
1592
1596
  weightToken1: 4000,
1593
1597
  },
1598
+ [modeCampaigns.Kim_Ichi_SSD_Mode_Kim]: {
1599
+ campaignType: Campaign.CLAMM,
1600
+ computeChainId: ChainId.MODE,
1601
+ hooks: [],
1602
+ poolAddress: "0x86D9d9dd7A2c3146c6FAd51646F210Cb2E5FC12F",
1603
+ whitelist: ["0x70F4A63DD7e81Cf43B8b0E1cf09a8fc70B7C278b"],
1604
+ blacklist: [],
1605
+ url: "https://app.kim.exchange/pools/vaults/ichi/0x70f4a63dd7e81cf43b8b0e1cf09a8fc70b7c278b",
1606
+ forwarders: [],
1607
+ isOutOfRangeIncentivized: false,
1608
+ weightFees: 2000,
1609
+ weightToken0: 4000,
1610
+ weightToken1: 4000,
1611
+ },
1594
1612
  [modeCampaigns.Kim_Gamma_WETH_KIM_Mode]: {
1595
1613
  campaignType: Campaign.CLAMM,
1596
1614
  computeChainId: ChainId.MODE,
@@ -1678,6 +1696,48 @@ const ModeInterfaceCampaigns = {
1678
1696
  weightToken0: 4000,
1679
1697
  weightToken1: 4000,
1680
1698
  },
1699
+ [modeCampaigns.Kim_Steer_SSS_V2_weETH_ETH]: {
1700
+ campaignType: Campaign.CLAMM,
1701
+ computeChainId: ChainId.MODE,
1702
+ hooks: [],
1703
+ poolAddress: "0xE24C8feB38ca2B18b542994BFBA7E70880171035",
1704
+ whitelist: ["0x5Aa27D5d8aff8Cd5e683e23812124AcE4aA5af7D"],
1705
+ blacklist: [],
1706
+ url: "https://app.kim.exchange/pools/vaults/0x5aa27d5d8aff8cd5e683e23812124ace4aa5af7d",
1707
+ forwarders: [],
1708
+ isOutOfRangeIncentivized: false,
1709
+ weightFees: 2000,
1710
+ weightToken0: 4000,
1711
+ weightToken1: 4000,
1712
+ },
1713
+ [modeCampaigns.Kim_Steer_CRS_V2_ezETH_ETH]: {
1714
+ campaignType: Campaign.CLAMM,
1715
+ computeChainId: ChainId.MODE,
1716
+ hooks: [],
1717
+ poolAddress: "0xD9a06f63E523757973ffd1a4606A1260252636D2",
1718
+ whitelist: ["0x83556D8bBa69bdD159f50B2127ccc88bebF73e39"],
1719
+ blacklist: [],
1720
+ url: "https://app.kim.exchange/pools/vaults/0x83556d8bba69bdd159f50b2127ccc88bebf73e39",
1721
+ forwarders: [],
1722
+ isOutOfRangeIncentivized: false,
1723
+ weightFees: 2000,
1724
+ weightToken0: 4000,
1725
+ weightToken1: 4000,
1726
+ },
1727
+ [modeCampaigns.Kim_Ichi_SSD_wMLT_Mode]: {
1728
+ campaignType: Campaign.CLAMM,
1729
+ computeChainId: ChainId.MODE,
1730
+ hooks: [],
1731
+ poolAddress: "0xA186548320Bdb79c714719e107aD5753eCb452d4",
1732
+ whitelist: ["0x2660F0291F62FE9ce515b88B8080ce829e5c01c3"],
1733
+ blacklist: [],
1734
+ url: "https://app.kim.exchange/pools/vaults/ichi/0x2660f0291f62fe9ce515b88b8080ce829e5c01c3",
1735
+ forwarders: [],
1736
+ isOutOfRangeIncentivized: false,
1737
+ weightFees: 2000,
1738
+ weightToken0: 4000,
1739
+ weightToken1: 4000,
1740
+ },
1681
1741
  [modeCampaigns.Kim_V4_WETH_MODE_Mode]: {
1682
1742
  campaignType: Campaign.CLAMM,
1683
1743
  computeChainId: ChainId.MODE,