@merkl/api 0.10.240 → 0.10.242
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.
- package/dist/src/libs/campaigns/utils/getEulerV2Vaults.js +3 -1
- package/dist/src/libs/tokens/balances.d.ts +1 -1
- package/dist/src/libs/tokens/balances.js +34 -33
- package/dist/src/modules/v4/interaction/interaction.service.js +7 -0
- package/dist/src/modules/v4/token/token.service.js +1 -2
- package/dist/src/routes/v1/allowances.js +2 -2
- package/dist/tsconfig.package.tsbuildinfo +1 -1
- package/package.json +1 -1
|
@@ -9,12 +9,14 @@ import { safeFetchLogs } from "./fetchLogs";
|
|
|
9
9
|
const VAULT_LENS_ADDRESS = {
|
|
10
10
|
[ChainId.MAINNET]: "0x57904B4DF131F00DEE9BB75a8FA1D27744035c90",
|
|
11
11
|
[ChainId.SWELL]: "0x7caA3c60D730D94D4b5E0E80E3b7D461fD153526",
|
|
12
|
+
[ChainId.BASE]: "0xc20B6e1d52ce377a450512958EEE8142063436CD",
|
|
12
13
|
};
|
|
13
14
|
const EVC_CREATION_BLOCK = {
|
|
14
15
|
[ChainId.MAINNET]: 20529207,
|
|
15
16
|
[ChainId.SWELL]: 485320,
|
|
17
|
+
[ChainId.BASE]: 24127584,
|
|
16
18
|
};
|
|
17
|
-
const eulerChainds = [ChainId.MAINNET, ChainId.SWELL];
|
|
19
|
+
const eulerChainds = [ChainId.MAINNET, ChainId.SWELL, ChainId.BASE];
|
|
18
20
|
async function getEulerV2Vaults() {
|
|
19
21
|
let vaults = [];
|
|
20
22
|
for (const chainId of eulerChainds) {
|
|
@@ -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<
|
|
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, ETH_ADDRESS, ETH_ZKSYNC_ADDRESS, 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
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
if (chainId === ChainId.ZKSYNC && tokenAddress === ETH_ZKSYNC_ADDRESS) {
|
|
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
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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];
|
|
@@ -53,7 +54,7 @@ export async function getUserBalances(user, chainId, tokenAddresses) {
|
|
|
53
54
|
},
|
|
54
55
|
};
|
|
55
56
|
}
|
|
56
|
-
const tokenListAddresses = Object.keys(tokens).filter(t => t !==
|
|
57
|
+
const tokenListAddresses = Object.keys(tokens).filter(t => t !== ETH_ADDRESS);
|
|
57
58
|
const ERC20_Interface = Erc20__factory.createInterface();
|
|
58
59
|
const calls = [];
|
|
59
60
|
for (const tokenAddress of tokenListAddresses) {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ETH_ZKSYNC_ADDRESS } from "@sdk";
|
|
1
2
|
import { decodeFunctionResult, encodeFunctionData, parseAbi } from "viem";
|
|
2
3
|
import { ChainInteractionService } from "../chainInteraction";
|
|
3
4
|
import { EnsoService } from "../enso/enso.service";
|
|
@@ -61,6 +62,9 @@ export class InteractionService {
|
|
|
61
62
|
* @returns approved?, approval tx & allowance amount
|
|
62
63
|
*/
|
|
63
64
|
static async getApproval(chainId, owner, spender, tokenAddress, amount) {
|
|
65
|
+
// Normalizing ETH on ZKSync
|
|
66
|
+
if (tokenAddress === ETH_ZKSYNC_ADDRESS)
|
|
67
|
+
tokenAddress = ETH_ZKSYNC_ADDRESS;
|
|
64
68
|
//TODO: add utils to make using viem type-safety more concise
|
|
65
69
|
const abi = parseAbi([
|
|
66
70
|
"function approve(address, uint256) returns (bool)",
|
|
@@ -95,6 +99,9 @@ export class InteractionService {
|
|
|
95
99
|
};
|
|
96
100
|
}
|
|
97
101
|
static async getTransaction(provider, chainId, protocolId, identifier, userAddress, fromTokenAddress, fromTokenAmount, slippage) {
|
|
102
|
+
// Normalizing ETH on ZKSync
|
|
103
|
+
if (fromTokenAddress === ETH_ZKSYNC_ADDRESS)
|
|
104
|
+
fromTokenAddress = ETH_ZKSYNC_ADDRESS;
|
|
98
105
|
if (provider === "zap")
|
|
99
106
|
return await KyberZapService.getTransaction(chainId, protocolId, identifier, userAddress, fromTokenAddress, fromTokenAmount, slippage);
|
|
100
107
|
const { tx, ...quote } = await EnsoService.getTransaction({
|
|
@@ -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
|
|
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()) ?? ""];
|
|
@@ -3,13 +3,13 @@ import checkQueryChainIdValidity from "../../hooks/checkQueryChainIdValidity";
|
|
|
3
3
|
import { getUserBalances } from "../../libs/tokens/balances";
|
|
4
4
|
import { executeSimple } from "../../utils/execute";
|
|
5
5
|
import { throwOnInvalidAddress } from "../../utils/throw";
|
|
6
|
-
import { ChainId, ERC20Interface, registry } from "@sdk";
|
|
6
|
+
import { ChainId, ERC20Interface, ETH_ADDRESS, registry } from "@sdk";
|
|
7
7
|
import { t } from "elysia";
|
|
8
8
|
export async function getUserAllowances(user, spenders, tokens, chainId, additionalTokenAddresses) {
|
|
9
9
|
/** Filtered tokens list */
|
|
10
10
|
const filteredTokens = Object.keys(tokens).reduce((filteredTokensList, tokenAddress) => {
|
|
11
11
|
if (tokenAddress === "0x0000000000000000000000000000000000001010" ||
|
|
12
|
-
tokenAddress ===
|
|
12
|
+
tokenAddress === ETH_ADDRESS ||
|
|
13
13
|
tokenAddress === registry(ChainId.MAINNET)?.veANGLE)
|
|
14
14
|
return filteredTokensList;
|
|
15
15
|
if (!tokens[tokenAddress]?.wrappingMethod || tokens[tokenAddress]?.wrappingMethod !== "Convex") {
|