@merkl/api 0.10.239 → 0.10.241

Sign up to get free protection for your applications and to get access to all the features.
@@ -905,6 +905,7 @@ declare const eden: {
905
905
  name?: string | undefined;
906
906
  chainId?: any;
907
907
  address?: string | undefined;
908
+ displaySymbol?: string | undefined;
908
909
  verified?: boolean | undefined;
909
910
  test?: boolean | undefined;
910
911
  };
@@ -959,6 +960,7 @@ declare const eden: {
959
960
  name?: string | undefined;
960
961
  chainId?: any;
961
962
  address?: string | undefined;
963
+ displaySymbol?: string | undefined;
962
964
  verified?: boolean | undefined;
963
965
  test?: boolean | undefined;
964
966
  };
@@ -3785,6 +3787,7 @@ export declare const MerklApi: (domain: string | import("elysia").default<"", fa
3785
3787
  name?: string | undefined;
3786
3788
  chainId?: any;
3787
3789
  address?: string | undefined;
3790
+ displaySymbol?: string | undefined;
3788
3791
  verified?: boolean | undefined;
3789
3792
  test?: boolean | undefined;
3790
3793
  };
@@ -3818,6 +3821,7 @@ export declare const MerklApi: (domain: string | import("elysia").default<"", fa
3818
3821
  name?: string | undefined;
3819
3822
  chainId?: any;
3820
3823
  address?: string | undefined;
3824
+ displaySymbol?: string | undefined;
3821
3825
  verified?: boolean | undefined;
3822
3826
  test?: boolean | undefined;
3823
3827
  };
@@ -7089,6 +7093,7 @@ export declare const MerklApi: (domain: string | import("elysia").default<"", fa
7089
7093
  name?: string | undefined;
7090
7094
  chainId?: any;
7091
7095
  address?: string | undefined;
7096
+ displaySymbol?: string | undefined;
7092
7097
  verified?: boolean | undefined;
7093
7098
  test?: boolean | undefined;
7094
7099
  };
@@ -7143,6 +7148,7 @@ export declare const MerklApi: (domain: string | import("elysia").default<"", fa
7143
7148
  name?: string | undefined;
7144
7149
  chainId?: any;
7145
7150
  address?: string | undefined;
7151
+ displaySymbol?: string | undefined;
7146
7152
  verified?: boolean | undefined;
7147
7153
  test?: boolean | undefined;
7148
7154
  };
@@ -1047,6 +1047,7 @@ declare const app: Elysia<"", false, {
1047
1047
  name?: string | undefined;
1048
1048
  chainId?: any;
1049
1049
  address?: string | undefined;
1050
+ displaySymbol?: string | undefined;
1050
1051
  verified?: boolean | undefined;
1051
1052
  test?: boolean | undefined;
1052
1053
  };
@@ -1080,6 +1081,7 @@ declare const app: Elysia<"", false, {
1080
1081
  name?: string | undefined;
1081
1082
  chainId?: any;
1082
1083
  address?: string | undefined;
1084
+ displaySymbol?: string | undefined;
1083
1085
  verified?: boolean | undefined;
1084
1086
  test?: boolean | undefined;
1085
1087
  };
@@ -6,6 +6,6 @@ type ReturnType = {
6
6
  decimals: number;
7
7
  };
8
8
  };
9
- export declare function getOnlyUserBalance(chainId: number, userAddress: string, tokenAddresses: string[]): Promise<UncachedResult<ReturnType>>;
9
+ export declare function getOnlyUserBalance(chainId: number, userAddress: string, tokenAddresses: string[]): Promise<ReturnType>;
10
10
  export declare function getUserBalances(user: string, chainId: number, tokenAddresses?: string[]): Promise<UncachedResult<ReturnType>>;
11
11
  export {};
@@ -1,42 +1,43 @@
1
- import { Erc20__factory } from "@sdk";
1
+ import { ChainId, ChainInteractionService, Erc20__factory, EthOnZKSync_INTERFACE, NETWORK_LABELS, } from "@sdk";
2
2
  import { log } from "../../utils/logger";
3
3
  import { getTokensListWithCache } from "../getTokensList";
4
4
  export async function getOnlyUserBalance(chainId, userAddress, tokenAddresses) {
5
5
  const calls = [];
6
6
  const ERC20_Interface = Erc20__factory.createInterface();
7
7
  for (const tokenAddress of tokenAddresses) {
8
- calls.push({
9
- allowFailure: true,
10
- callData: ERC20_Interface.encodeFunctionData("balanceOf", [userAddress]),
11
- target: tokenAddress,
12
- });
8
+ if (chainId === ChainId.ZKSYNC && tokenAddress === "0x000000000000000000000000000000000000800A") {
9
+ calls.push({
10
+ allowFailure: true,
11
+ callData: EthOnZKSync_INTERFACE.encodeFunctionData("balanceOf", [userAddress]),
12
+ target: tokenAddress,
13
+ });
14
+ }
15
+ else {
16
+ calls.push({
17
+ allowFailure: true,
18
+ callData: ERC20_Interface.encodeFunctionData("balanceOf", [userAddress]),
19
+ target: tokenAddress,
20
+ });
21
+ }
13
22
  }
14
- return {
15
- cached: false,
16
- call: {
17
- callData: calls,
18
- handler: () => { },
19
- reducer: async (result) => {
20
- const res = {};
21
- for (let j = 0; j < tokenAddresses.length; j++) {
22
- const tokenAddress = tokenAddresses[j];
23
- let balance = "0";
24
- try {
25
- balance = ERC20_Interface.decodeFunctionResult("balanceOf", result[j])[0]?.toString();
26
- }
27
- catch (_error) {
28
- log.local(`❌ Failed to call balanceOf for ${tokenAddress} on ${chainId}`);
29
- }
30
- res[tokenAddress] = {
31
- balance: balance,
32
- decimals: 0,
33
- symbol: "",
34
- };
35
- }
36
- return res;
37
- },
38
- },
39
- };
23
+ const result = await ChainInteractionService(chainId).fetchState(calls);
24
+ const res = {};
25
+ for (let j = 0; j < tokenAddresses.length; j++) {
26
+ const tokenAddress = tokenAddresses[j];
27
+ let balance = "0";
28
+ try {
29
+ balance = ERC20_Interface.decodeFunctionResult("balanceOf", result[j].returnData)[0]?.toString();
30
+ }
31
+ catch (_error) {
32
+ log.local(`❌ Failed to call balanceOf for ${tokenAddress} on ${NETWORK_LABELS[chainId]}`);
33
+ }
34
+ res[tokenAddress] = {
35
+ balance: balance,
36
+ decimals: 0,
37
+ symbol: "",
38
+ };
39
+ }
40
+ return res;
40
41
  }
41
42
  export async function getUserBalances(user, chainId, tokenAddresses) {
42
43
  const tokens = (await getTokensListWithCache())?.[chainId];
@@ -925,6 +925,7 @@ export declare const v4: Elysia<"/v4", false, {
925
925
  name?: string | undefined;
926
926
  chainId?: any;
927
927
  address?: string | undefined;
928
+ displaySymbol?: string | undefined;
928
929
  verified?: boolean | undefined;
929
930
  test?: boolean | undefined;
930
931
  };
@@ -958,6 +959,7 @@ export declare const v4: Elysia<"/v4", false, {
958
959
  name?: string | undefined;
959
960
  chainId?: any;
960
961
  address?: string | undefined;
962
+ displaySymbol?: string | undefined;
961
963
  verified?: boolean | undefined;
962
964
  test?: boolean | undefined;
963
965
  };
@@ -82,6 +82,7 @@ export declare const TokenController: Elysia<"/tokens", false, {
82
82
  name?: string | undefined;
83
83
  chainId?: any;
84
84
  address?: string | undefined;
85
+ displaySymbol?: string | undefined;
85
86
  verified?: boolean | undefined;
86
87
  test?: boolean | undefined;
87
88
  };
@@ -115,6 +116,7 @@ export declare const TokenController: Elysia<"/tokens", false, {
115
116
  name?: string | undefined;
116
117
  chainId?: any;
117
118
  address?: string | undefined;
119
+ displaySymbol?: string | undefined;
118
120
  verified?: boolean | undefined;
119
121
  test?: boolean | undefined;
120
122
  };
@@ -28,6 +28,7 @@ export declare const FindUniqueTokenDto: import("@sinclair/typebox").TObject<{
28
28
  }>;
29
29
  export declare const GetTokenQueryDto: import("@sinclair/typebox").TObject<{
30
30
  symbol: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
31
+ displaySymbol: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
31
32
  chainId: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TEnum<any>>;
32
33
  address: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
33
34
  name: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
@@ -18,6 +18,7 @@ export const FindUniqueTokenDto = t.Object({
18
18
  });
19
19
  export const GetTokenQueryDto = t.Object({
20
20
  symbol: t.Optional(t.String()),
21
+ displaySymbol: t.Optional(t.String()), // To filter by displaySymbol or if null symbol
21
22
  chainId: t.Optional(t.Enum(ChainId)),
22
23
  address: t.Optional(t.String()),
23
24
  name: t.Optional(t.String()),
@@ -39,7 +39,17 @@ export class TokenRepository {
39
39
  { symbol: { equals: query.symbol, mode: "insensitive" } },
40
40
  { displaySymbol: { equals: query.symbol, mode: "insensitive" } },
41
41
  ]
42
- : undefined,
42
+ : query.displaySymbol
43
+ ? [
44
+ {
45
+ displaySymbol: {
46
+ not: "",
47
+ },
48
+ symbol: { equals: query.displaySymbol, mode: "insensitive" },
49
+ },
50
+ { displaySymbol: { equals: query.displaySymbol, mode: "insensitive" } },
51
+ ]
52
+ : undefined,
43
53
  address: query.address ? { equals: query.address, mode: "insensitive" } : undefined,
44
54
  chainId: query.chainId ? { equals: query.chainId } : undefined,
45
55
  name: query.name ? { contains: query.name, mode: "insensitive" } : undefined,
@@ -1,6 +1,5 @@
1
1
  import { getTokensListWithCache } from "../../../libs/getTokensList";
2
2
  import { getOnlyUserBalance } from "../../../libs/tokens/balances";
3
- import { executeSimple } from "../../../utils/execute";
4
3
  import { log } from "../../../utils/logger";
5
4
  import { apiDbClient } from "../../../utils/prisma";
6
5
  import { Prisma } from "../../../../database/api/.generated";
@@ -22,7 +21,7 @@ export class TokenService {
22
21
  * Fetches balances of provided tokens
23
22
  */
24
23
  static async fetchBalances(chainId, userAddress, tokens) {
25
- const balances = await executeSimple(chainId, getOnlyUserBalance(chainId, userAddress, tokens.map(t => t.address)));
24
+ const balances = await getOnlyUserBalance(chainId, userAddress, tokens.map(t => t.address));
26
25
  const tokensWithBalances = tokens.map(t => {
27
26
  const balance = balances[t.address] ??
28
27
  balances[Object.keys(balances).find(a => a?.toLowerCase() === t.address?.toLowerCase()) ?? ""];