@merkl/api 0.18.5 → 0.18.6

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.
@@ -72,7 +72,6 @@ export class TokenService {
72
72
  }
73
73
  static async fetchOnChain(token) {
74
74
  const onchainData = await TokenRepository.getTokenInfo(token);
75
- //TODO: find a way to get the icon
76
75
  return {
77
76
  chainId: token.chainId,
78
77
  address: token.address,
@@ -80,9 +79,19 @@ export class TokenService {
80
79
  ...Object.assign({ name: "unknown", decimals: 18, symbol: "UNKNOWN", verified: false, isTest: false, isNative: false }, onchainData),
81
80
  };
82
81
  }
82
+ static async tryToFillWithCoingeckoIcons() {
83
+ // 1 - Find coingecko price sources
84
+ let priceSources = await PriceService.findManyPriceSources({ method: "COINGECKO" });
85
+ // 2 - Find tokens with missing logos
86
+ const missingIcons = await TokenService.findMany({ missingIcons: true });
87
+ // 3 - Do the intersection of both
88
+ priceSources = priceSources.filter(p => missingIcons.find(t => t.symbol === p.symbol || t.address === p.symbol));
89
+ log.info(`found ${priceSources.length} tokens with missing icons on coingecko.`);
90
+ // 4 - Loop through each and try to get the icon
91
+ }
83
92
  static async fetchManyOnChain(chainId, addresses) {
84
93
  const tokens = {};
85
- //Batch onchain calls together when multiples
94
+ // Batch onchain calls together when multiples
86
95
  for (const address of addresses) {
87
96
  tokens[address] = await TokenService.fetchOnChain({ chainId, address });
88
97
  }
@@ -128,77 +137,6 @@ export class TokenService {
128
137
  await TokenService.updateAddressPrices(address, price);
129
138
  }
130
139
  }
131
- /**
132
- * Get all tokens from https://github.com/AngleProtocol/angle-token-list and override icons from it
133
- * TODO: use the bucket
134
- */
135
- static async fillTokenAndIconsFromTokenList() {
136
- const tokenList = await getTokensListWithCache();
137
- for (const chain of Object.keys(tokenList)) {
138
- for (const [symbol, token] of Object.entries(tokenList[chain])) {
139
- if (!(await TokenRepository.findUnique(TokenService.hashId({ chainId: Number.parseInt(chain), address: token.address })))) {
140
- try {
141
- const res = await TokenRepository.create({
142
- id: TokenService.hashId({ chainId: Number.parseInt(chain), address: token.address }),
143
- chainId: Number.parseInt(chain),
144
- address: token.address,
145
- name: token.name,
146
- symbol: token.symbol,
147
- verified: true,
148
- decimals: token.decimals,
149
- icon: token.logoURI,
150
- isTest: false,
151
- isNative: false,
152
- });
153
- log.local(`Token created: ${res?.symbol} on ${NETWORK_LABELS[Number.parseInt(chain)]}`);
154
- }
155
- catch (e) {
156
- console.error(e);
157
- }
158
- }
159
- try {
160
- await apiDbClient.token.update({
161
- data: {
162
- chainId: Number.parseInt(chain),
163
- address: token.address,
164
- name: token.name,
165
- symbol: token.symbol,
166
- verified: true,
167
- decimals: token.decimals,
168
- icon: token.logoURI,
169
- },
170
- where: {
171
- chainId_address: {
172
- chainId: Number.parseInt(chain),
173
- address: token.address,
174
- },
175
- },
176
- });
177
- }
178
- catch (e) {
179
- console.error(e);
180
- }
181
- try {
182
- const tokensWithSameSymbol = await apiDbClient.token.findMany({
183
- select: { chainId: true, address: true },
184
- where: { symbol: { equals: symbol, mode: "insensitive" } },
185
- });
186
- for (const dbToken of tokensWithSameSymbol) {
187
- await apiDbClient.token.update({
188
- data: { icon: token.logoURI },
189
- where: {
190
- chainId_address: {
191
- chainId: dbToken.chainId,
192
- address: dbToken.address,
193
- },
194
- },
195
- });
196
- }
197
- }
198
- catch (_err) { }
199
- }
200
- }
201
- }
202
140
  /**
203
141
  * Create token on database
204
142
  * @param chainId
@@ -321,10 +259,6 @@ export class TokenService {
321
259
  }, chainId);
322
260
  }
323
261
  static async update(id, data) {
324
- // let iconUri = data.icon;
325
- // if (data.iconFile) {
326
- // iconUri = await BucketService.upload("merkl-assets", `/tokens/${id}`, data.iconFile.stream(), true);
327
- // }
328
262
  return await TokenRepository.update(id, data);
329
263
  }
330
264
  static async notionWebhook(body) {
@@ -381,4 +315,76 @@ export class TokenService {
381
315
  verified: isVerified,
382
316
  });
383
317
  }
318
+ /**
319
+ * Get all tokens from https://github.com/AngleProtocol/angle-token-list and override icons from it
320
+ * TODO: use the bucket
321
+ * @deprecated Should be useless now that the token list is not used anymore
322
+ */
323
+ static async fillTokenAndIconsFromTokenList() {
324
+ const tokenList = await getTokensListWithCache();
325
+ for (const chain of Object.keys(tokenList)) {
326
+ for (const [symbol, token] of Object.entries(tokenList[chain])) {
327
+ if (!(await TokenRepository.findUnique(TokenService.hashId({ chainId: Number.parseInt(chain), address: token.address })))) {
328
+ try {
329
+ const res = await TokenRepository.create({
330
+ id: TokenService.hashId({ chainId: Number.parseInt(chain), address: token.address }),
331
+ chainId: Number.parseInt(chain),
332
+ address: token.address,
333
+ name: token.name,
334
+ symbol: token.symbol,
335
+ verified: true,
336
+ decimals: token.decimals,
337
+ icon: token.logoURI,
338
+ isTest: false,
339
+ isNative: false,
340
+ });
341
+ log.local(`Token created: ${res?.symbol} on ${NETWORK_LABELS[Number.parseInt(chain)]}`);
342
+ }
343
+ catch (e) {
344
+ console.error(e);
345
+ }
346
+ }
347
+ try {
348
+ await apiDbClient.token.update({
349
+ data: {
350
+ chainId: Number.parseInt(chain),
351
+ address: token.address,
352
+ name: token.name,
353
+ symbol: token.symbol,
354
+ verified: true,
355
+ decimals: token.decimals,
356
+ icon: token.logoURI,
357
+ },
358
+ where: {
359
+ chainId_address: {
360
+ chainId: Number.parseInt(chain),
361
+ address: token.address,
362
+ },
363
+ },
364
+ });
365
+ }
366
+ catch (e) {
367
+ console.error(e);
368
+ }
369
+ try {
370
+ const tokensWithSameSymbol = await apiDbClient.token.findMany({
371
+ select: { chainId: true, address: true },
372
+ where: { symbol: { equals: symbol, mode: "insensitive" } },
373
+ });
374
+ for (const dbToken of tokensWithSameSymbol) {
375
+ await apiDbClient.token.update({
376
+ data: { icon: token.logoURI },
377
+ where: {
378
+ chainId_address: {
379
+ chainId: dbToken.chainId,
380
+ address: dbToken.address,
381
+ },
382
+ },
383
+ });
384
+ }
385
+ }
386
+ catch (_err) { }
387
+ }
388
+ }
389
+ }
384
390
  }
@@ -19,7 +19,7 @@ export default (app) => app.get("/app", async () => {
19
19
  if (!json.tokens[token.chainId]) {
20
20
  json.tokens[token.chainId] = {};
21
21
  }
22
- if (!json.tokens[token.chainId][token.address]) {
22
+ if (!json.tokens[token.chainId][token.address] && token.icon?.length > 0) {
23
23
  json.tokens[token.chainId][token.address] = {
24
24
  address: token.address,
25
25
  chainId: token.chainId,
@@ -26,7 +26,7 @@ export default class PriceService {
26
26
  });
27
27
  };
28
28
  async fetchPrices() {
29
- const tokenPriceSources = await PriceSourceService.getManyPriceSources();
29
+ const tokenPriceSources = await PriceSourceService.findManyPriceSources();
30
30
  /**
31
31
  * @description Factory pricer's call to get prices from different sources
32
32
  */