@merkl/api 0.18.4 → 0.18.5

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.
@@ -3,6 +3,7 @@ import { getTokensListWithCache } from "@/libs/getTokensList";
3
3
  import { getOnlyUserBalance } from "@/libs/tokens/balances";
4
4
  import { log } from "@/utils/logger";
5
5
  import { apiDbClient } from "@/utils/prisma";
6
+ import { throwOnInvalidRequiredAddress, throwOnUnsupportedChainId } from "@/utils/throw";
6
7
  import { Prisma } from "@db/api";
7
8
  import { ChainInteractionService, DistributionCreatorService, NETWORK_LABELS, bigIntToNumber, } from "@sdk";
8
9
  import { getAddress, parseUnits } from "viem";
@@ -330,14 +331,15 @@ export class TokenService {
330
331
  const env = process.env.ENV === "prod" ? "production" : process.env.ENV;
331
332
  const bucket = new BucketService(`merkl-${env}-tokens`, `angle-${env}-1`);
332
333
  const properties = body.data.properties;
333
- const icon = properties["Icon"].files?.[0]?.file.url;
334
+ const icon = properties.Icon.files?.[0]?.file.url;
334
335
  const iconFile = await fetch(icon);
335
336
  const mimeType = iconFile.headers.get("content-type");
336
337
  const extension = mimeType.split("/")[1];
337
- const address = properties["Address"].rich_text[0].plain_text;
338
+ const address = throwOnInvalidRequiredAddress(properties.Address.rich_text[0].plain_text);
338
339
  const chainId = properties["Chain ID"].number;
339
- const symbol = properties["Symbol"].rich_text[0]?.plain_text;
340
- const isVerified = properties["Verified"].checkbox;
340
+ throwOnUnsupportedChainId(chainId);
341
+ const displaySymbol = properties.Symbol.rich_text[0]?.plain_text;
342
+ const isVerified = properties.Verified.checkbox;
341
343
  const coingeckoApiId = properties["CoinGecko API ID"].rich_text[0].plain_text;
342
344
  const byteArray = await iconFile.bytes();
343
345
  const [token] = await TokenService.getManyOrCreate([
@@ -347,7 +349,7 @@ export class TokenService {
347
349
  },
348
350
  ]);
349
351
  if (!token || !token.name)
350
- throw new HttpError(`Failed to fetch on-chain data for token ${symbol} (${address} on chainId ${chainId}).`);
352
+ throw new HttpError(`Failed to fetch on-chain data for token ${token?.symbol} (${address} on chainId ${chainId}).`);
351
353
  try {
352
354
  await bucket.pushRaw(`${chainId}/${address}.${extension}`, byteArray, {
353
355
  type: mimeType,
@@ -361,7 +363,11 @@ export class TokenService {
361
363
  }
362
364
  if (coingeckoApiId) {
363
365
  try {
364
- await PriceService.createPriceSource({ method: "COINGECKO", symbol, args: { ticker: coingeckoApiId } });
366
+ await PriceService.createPriceSource({
367
+ method: "COINGECKO",
368
+ symbol: token.symbol,
369
+ args: { ticker: coingeckoApiId },
370
+ });
365
371
  }
366
372
  catch (err) {
367
373
  console.error("Failed to create price source.");
@@ -370,7 +376,7 @@ export class TokenService {
370
376
  }
371
377
  return await TokenService.update(token.id, {
372
378
  icon: token.icon,
373
- displaySymbol: symbol && symbol !== "" ? symbol : token.symbol,
379
+ displaySymbol: displaySymbol && displaySymbol !== "" ? displaySymbol : token.symbol,
374
380
  name: token.name,
375
381
  verified: isVerified,
376
382
  });