@merkl/api 0.20.35 → 0.20.36

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.
@@ -1,5 +1,5 @@
1
1
  import type { ProtocolId } from "@/modules/v4/protocol/protocol.model";
2
- import type { Campaign as CampaignEnum, CampaignParameters, ChainId } from "@sdk";
2
+ import { type Campaign as CampaignEnum, type CampaignParameters, type ChainId } from "@sdk";
3
3
  import type { MetadataBuilder } from "../interface";
4
4
  type campaignType = CampaignEnum.RADIANT;
5
5
  export declare class RadiantMetadata implements MetadataBuilder<campaignType> {
@@ -1,11 +1,28 @@
1
+ import { log } from "@/utils/logger";
1
2
  import { OpportunityAction } from "@db/api";
3
+ import { ChainInteractionService, NETWORK_LABELS, RadiantInterface, } from "@sdk";
2
4
  import { getAddress } from "viem";
3
5
  export class RadiantMetadata {
4
6
  async build(computeChainId, params, subType) {
7
+ const tokens = [{ chainId: computeChainId, address: params.targetToken }];
8
+ try {
9
+ const result = await ChainInteractionService(computeChainId).fetchState([
10
+ {
11
+ target: params.targetToken,
12
+ allowFailure: true,
13
+ callData: RadiantInterface.encodeFunctionData("UNDERLYING_ASSET_ADDRESS"),
14
+ },
15
+ ]);
16
+ const underlyingAddress = getAddress(RadiantInterface.decodeFunctionResult("UNDERLYING_ASSET_ADDRESS", result[0].returnData)[0]);
17
+ tokens.push({ chainId: computeChainId, address: underlyingAddress });
18
+ }
19
+ catch {
20
+ log.warn(`failed to fetch underlying asset address on ${NETWORK_LABELS[computeChainId]} for radiant token ${params.targetToken}`);
21
+ }
5
22
  return {
6
23
  action: subType <= 1 ? OpportunityAction.LEND : OpportunityAction.BORROW,
7
24
  name: [subType <= 1 ? "Lend" : "Borrow", params.symbolTargetToken].join(" "),
8
- tokens: [{ chainId: computeChainId, address: params.targetToken }],
25
+ tokens,
9
26
  mainProtocol: "radiant",
10
27
  explorerAddress: getAddress(params.targetToken),
11
28
  };
@@ -8,8 +8,6 @@ import { Prisma } from "@db/api";
8
8
  import { ChainInteractionService, DistributionCreatorService, NETWORK_LABELS, bigIntToNumber, } from "@sdk";
9
9
  import { getAddress, parseUnits } from "viem";
10
10
  import { BucketService } from "../bucket/bucket.service";
11
- import { CacheService } from "../cache";
12
- import { TTLPresets } from "../cache/cache.model";
13
11
  import { IconService } from "../icon/icon.service";
14
12
  import { PriceService } from "../price";
15
13
  import { TokenRepository } from "./token.repository";
@@ -272,17 +270,15 @@ export class TokenService {
272
270
  }));
273
271
  }
274
272
  static async getValidRewardTokens(chainId) {
275
- return await CacheService.wrap(TTLPresets.MIN_5, async (chainId) => {
276
- const validRewardTokens = await DistributionCreatorService(chainId).validRewardTokens();
277
- return (await TokenRepository.findList(chainId, validRewardTokens.map(t => getAddress(t.token)))).map(x => {
278
- return {
279
- ...x,
280
- minimumAmountPerHour: validRewardTokens
281
- .find(t => getAddress(t.token) === x.address)
282
- ?.minimumAmountPerEpoch.toString(),
283
- };
284
- });
285
- }, chainId);
273
+ const validRewardTokens = await DistributionCreatorService(chainId).validRewardTokens();
274
+ return (await TokenRepository.findList(chainId, validRewardTokens.map(t => getAddress(t.token)))).map(x => {
275
+ return {
276
+ ...x,
277
+ minimumAmountPerHour: validRewardTokens
278
+ .find(t => getAddress(t.token) === x.address)
279
+ ?.minimumAmountPerEpoch.toString(),
280
+ };
281
+ });
286
282
  }
287
283
  static async update(id, data) {
288
284
  return await TokenRepository.update(id, data);