@merkl/api 0.16.5 → 0.16.7

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.
@@ -113,6 +113,7 @@ export declare const TokenController: Elysia<"/tokens", false, {
113
113
  params: {};
114
114
  query: {
115
115
  tokenAddress?: string | undefined;
116
+ verified?: boolean | undefined;
116
117
  additionalTokenAddresses?: string[] | undefined;
117
118
  chainId: number;
118
119
  userAddress: string;
@@ -47,6 +47,7 @@ export declare const TokenDto: import("@sinclair/typebox").TObject<{
47
47
  export declare const GetTokenBalanceDto: import("@sinclair/typebox").TObject<{
48
48
  chainId: import("@sinclair/typebox").TNumber;
49
49
  userAddress: import("@sinclair/typebox").TString;
50
+ verified: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TBoolean>;
50
51
  tokenAddress: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
51
52
  additionalTokenAddresses: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TArray<import("@sinclair/typebox").TString>>;
52
53
  }>;
@@ -36,6 +36,7 @@ export const TokenDto = t.Object({
36
36
  export const GetTokenBalanceDto = t.Object({
37
37
  chainId: t.Numeric(),
38
38
  userAddress: t.String(),
39
+ verified: t.Optional(t.Boolean()),
39
40
  tokenAddress: t.Optional(t.String({ description: "If provided, the default verified token balances won't be included" })),
40
41
  additionalTokenAddresses: t.Optional(t.Array(t.String())),
41
42
  });
@@ -163,6 +163,19 @@ export declare abstract class TokenService {
163
163
  } & {
164
164
  price?: number | null | undefined;
165
165
  })[]>;
166
+ static findManyObjectPerAddress(query: GetTokenQueryModel): Promise<Record<string, {
167
+ symbol: string;
168
+ name: string | null;
169
+ id: string;
170
+ icon: string;
171
+ chainId: number;
172
+ address: string;
173
+ decimals: number;
174
+ verified: boolean;
175
+ isTest: boolean;
176
+ } & {
177
+ price?: number | null | undefined;
178
+ }>>;
166
179
  /**
167
180
  * Get value of tokens
168
181
  * @param tokenAmounts address/chain + amount of token
@@ -139,23 +139,6 @@ export class TokenService {
139
139
  catch (e) {
140
140
  console.error(e);
141
141
  }
142
- try {
143
- const res = await TokenRepository.create({
144
- id: TokenService.hashId({ chainId: Number.parseInt(chain), address: token.address }),
145
- chainId: Number.parseInt(chain),
146
- address: token.address,
147
- name: token.name,
148
- symbol: token.symbol,
149
- verified: true,
150
- decimals: token.decimals,
151
- icon: token.logoURI,
152
- isTest: false,
153
- });
154
- log.local(`Token created: ${res?.symbol} on ${NETWORK_LABELS[Number.parseInt(chain)]}`);
155
- }
156
- catch (e) {
157
- console.error(e);
158
- }
159
142
  }
160
143
  try {
161
144
  await apiDbClient.token.update({
@@ -236,6 +219,12 @@ export class TokenService {
236
219
  static async findMany(query) {
237
220
  return (await TokenRepository.findMany(query)).map(TokenService.format);
238
221
  }
222
+ static async findManyObjectPerAddress(query) {
223
+ return (await TokenService.findMany(query)).reduce((acc, token) => {
224
+ acc[token.address] = token;
225
+ return acc;
226
+ }, {});
227
+ }
239
228
  /**
240
229
  * Get value of tokens
241
230
  * @param tokenAmounts address/chain + amount of token
@@ -198,7 +198,7 @@ export declare const UserController: Elysia<"/users", false, {
198
198
  proofs: string[];
199
199
  }, "breakdowns"> & {
200
200
  breakdowns: {
201
- opportunity: import("..").Opportunity["model"];
201
+ opportunity: import("../opportunity").Opportunity["model"];
202
202
  claimed: bigint;
203
203
  amount: bigint;
204
204
  pending: bigint;
@@ -1,11 +1,11 @@
1
1
  import { Redis } from "../../cache";
2
+ import { TokenService } from "../../modules/v4/token";
2
3
  import { getLastBlockBeforeWithCache } from "../../utils/lastBlockBefore";
3
4
  import { BN2Number, ChainId, DAY, ERC20Interface } from "@sdk";
4
5
  import { t } from "elysia";
5
6
  import { utils } from "ethers";
6
7
  import moment from "moment";
7
8
  import checkQueryAddressValidity from "../../hooks/checkQueryAddressValidity";
8
- import { getTokensListWithCache } from "../../libs/getTokensList";
9
9
  import { batchMulticallCallWithRetry } from "../../utils/generic";
10
10
  import { log } from "../../utils/logger";
11
11
  import { providers } from "../../utils/providers";
@@ -32,13 +32,16 @@ const CONSTANTS = {
32
32
  ],
33
33
  };
34
34
  const getLostYield = async (user) => {
35
- const tokenList = await getTokensListWithCache();
36
35
  const result = {};
37
36
  const now = moment().unix();
38
37
  const LOOKBACK = 30 * DAY;
39
38
  const AVERAGING_PERIOD = 2 * DAY;
40
39
  const promises = Object.keys(CONSTANTS).map(chainId => (async () => {
41
40
  try {
41
+ const tokenList = await TokenService.findManyObjectPerAddress({
42
+ chainId: Number.parseInt(chainId),
43
+ verified: true,
44
+ });
42
45
  result[chainId] = {};
43
46
  for (const token of CONSTANTS[Number.parseInt(chainId)]) {
44
47
  result[chainId][token] = { total: 0, yield: 0 };
@@ -64,7 +67,7 @@ const getLostYield = async (user) => {
64
67
  const results = await batchMulticallCallWithRetry(Number.parseInt(chainId), { calls, blockNumber });
65
68
  let i = 0;
66
69
  for (const token of CONSTANTS[Number.parseInt(chainId)]) {
67
- const tokenDetails = tokenList[Number.parseInt(chainId)][utils.getAddress(token)];
70
+ const tokenDetails = tokenList[utils.getAddress(token)];
68
71
  const balance = ERC20Interface.decodeFunctionResult("balanceOf", results[i++].returnData)[0];
69
72
  result[chainId][token].total += BN2Number(balance, tokenDetails.decimals);
70
73
  }
@@ -263,7 +263,7 @@ export default class PriceService {
263
263
  this._prices[`r${xUpper}`] = this._prices[x];
264
264
  this._prices[`variableDebt${xUpper}`] = this._prices[x];
265
265
  }
266
- /** Fill all BorrowStaker prices */
266
+ /** Deprecated - Fill all BorrowStaker prices */
267
267
  const tokens = await getTokensListWithCache();
268
268
  for (const chainIdString of Object.keys(tokens)) {
269
269
  const chainId = Number.parseInt(chainIdString);