@merkl/api 0.10.146 → 0.10.148
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.
@@ -2,86 +2,100 @@ import { Redis } from "../../../cache";
|
|
2
2
|
import { batchMulticallCallWithRetry } from "../../../utils/generic";
|
3
3
|
import { log } from "../../../utils/logger";
|
4
4
|
import { providers } from "../../../utils/providers";
|
5
|
-
import { ChainId, ERC20Interface, EulerEVKInterface, EulerVaultLensInterface, EulerVault__factory, } from "@sdk";
|
5
|
+
import { ChainId, ERC20Interface, EulerEVKInterface, EulerVaultLensInterface, EulerVault__factory, NETWORK_LABELS, } from "@sdk";
|
6
6
|
import { getAddress } from "ethers/lib/utils";
|
7
7
|
import { fetchEulerVaultName } from "../campaignTypes/ERC20SubTypes/helpers/eulerVaultNames";
|
8
8
|
import { safeFetchLogs } from "./fetchLogs";
|
9
|
-
const VAULT_LENS_ADDRESS = {
|
9
|
+
const VAULT_LENS_ADDRESS = {
|
10
|
+
[ChainId.MAINNET]: "0x57904B4DF131F00DEE9BB75a8FA1D27744035c90",
|
11
|
+
[ChainId.SWELL]: "0x7caA3c60D730D94D4b5E0E80E3b7D461fD153526",
|
12
|
+
};
|
13
|
+
const EVC_CREATION_BLOCK = {
|
14
|
+
[ChainId.MAINNET]: 20529207,
|
15
|
+
[ChainId.SWELL]: 485320,
|
16
|
+
};
|
17
|
+
const eulerChainds = [ChainId.MAINNET, ChainId.SWELL];
|
10
18
|
async function getEulerV2Vaults() {
|
11
|
-
|
12
|
-
const
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
const callsCollatUnderlying = [];
|
41
|
-
const callsCollatUnderlyingSymbol = [];
|
42
|
-
for (const [index, _] of decodedVaults.entries()) {
|
43
|
-
const collatArray = EulerVaultLensInterface.decodeFunctionResult("getRecognizedCollateralsLTVInfo", resCollat[index].returnData)[0];
|
44
|
-
for (const collat of collatArray) {
|
45
|
-
callsCollatUnderlying.push({
|
46
|
-
allowFailure: true,
|
47
|
-
callData: EulerEVKInterface.encodeFunctionData("asset"),
|
48
|
-
target: collat.collateral,
|
49
|
-
}, {
|
50
|
-
allowFailure: true,
|
51
|
-
callData: EulerEVKInterface.encodeFunctionData("symbol"),
|
52
|
-
target: collat.collateral,
|
19
|
+
let vaults = [];
|
20
|
+
for (const chainId of eulerChainds) {
|
21
|
+
try {
|
22
|
+
const fromBlock = EVC_CREATION_BLOCK[chainId] ?? 0; // EVC contract creation block
|
23
|
+
const toBlock = await providers[chainId].getBlockNumber();
|
24
|
+
const logs = await safeFetchLogs(chainId, [EulerEVKInterface.getEventTopic("EVaultCreated")], [], fromBlock, toBlock);
|
25
|
+
const decodedVaults = await Promise.all(logs.map(async (log) => {
|
26
|
+
const aux = EulerEVKInterface.decodeEventLog("EVaultCreated", log.data, log.topics);
|
27
|
+
const name = (await EulerVault__factory.connect(log.address, providers[chainId]).name()).split(" ");
|
28
|
+
const vaultName = (await fetchEulerVaultName(getAddress(log.address), chainId)) ?? name[name.length - 1];
|
29
|
+
/** Respect the previous typing */
|
30
|
+
return {
|
31
|
+
address: log.address.toString(),
|
32
|
+
asset: aux[1].toString(),
|
33
|
+
chainId: chainId,
|
34
|
+
debtTokenAddress: aux[2].toString(),
|
35
|
+
name: vaultName,
|
36
|
+
};
|
37
|
+
}));
|
38
|
+
log.local(`fetched ${decodedVaults.length} vaults(s) on ${NETWORK_LABELS[chainId]} between blocks ${fromBlock} and ${toBlock}`);
|
39
|
+
/** Extra calls batch to get the collateral addresses */
|
40
|
+
const resCollat = await batchMulticallCallWithRetry(chainId, {
|
41
|
+
calls: decodedVaults.map(vault => {
|
42
|
+
return {
|
43
|
+
allowFailure: true,
|
44
|
+
callData: EulerVaultLensInterface.encodeFunctionData("getRecognizedCollateralsLTVInfo", [vault.address]),
|
45
|
+
target: VAULT_LENS_ADDRESS[ChainId.MAINNET],
|
46
|
+
};
|
47
|
+
}),
|
53
48
|
});
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
const collaterals = [];
|
73
|
-
for (const [_index, collat] of collatArray.entries()) {
|
74
|
-
const symbolUnderlying = ERC20Interface.decodeFunctionResult("symbol", resCollatUnderlyingSymbol[_index].returnData)[0];
|
75
|
-
collaterals.push({
|
76
|
-
address: collat.collateral,
|
77
|
-
symbolCollateral: EulerEVKInterface.decodeFunctionResult("symbol", resCollatUnderlying[2 * _index + 1].returnData)[0],
|
78
|
-
symbolUnderlying,
|
79
|
-
borrowLTV: collat.borrowLTV.toString(),
|
80
|
-
nameCollateral: (await fetchEulerVaultName(collat.collateral, chainId)) ?? symbolUnderlying,
|
49
|
+
const callsCollatUnderlying = [];
|
50
|
+
const callsCollatUnderlyingSymbol = [];
|
51
|
+
for (const [index, _] of decodedVaults.entries()) {
|
52
|
+
const collatArray = EulerVaultLensInterface.decodeFunctionResult("getRecognizedCollateralsLTVInfo", resCollat[index].returnData)[0];
|
53
|
+
for (const collat of collatArray) {
|
54
|
+
callsCollatUnderlying.push({
|
55
|
+
allowFailure: true,
|
56
|
+
callData: EulerEVKInterface.encodeFunctionData("asset"),
|
57
|
+
target: collat.collateral,
|
58
|
+
}, {
|
59
|
+
allowFailure: true,
|
60
|
+
callData: EulerEVKInterface.encodeFunctionData("symbol"),
|
61
|
+
target: collat.collateral,
|
62
|
+
});
|
63
|
+
}
|
64
|
+
}
|
65
|
+
const resCollatUnderlying = await batchMulticallCallWithRetry(ChainId.MAINNET, {
|
66
|
+
calls: callsCollatUnderlying,
|
81
67
|
});
|
68
|
+
for (let i = 0; i < resCollatUnderlying.length; i = i + 2) {
|
69
|
+
const underlyingToken = EulerEVKInterface.decodeFunctionResult("asset", resCollatUnderlying[i].returnData)[0];
|
70
|
+
callsCollatUnderlyingSymbol.push({
|
71
|
+
allowFailure: true,
|
72
|
+
callData: ERC20Interface.encodeFunctionData("symbol"),
|
73
|
+
target: underlyingToken,
|
74
|
+
});
|
75
|
+
}
|
76
|
+
const resCollatUnderlyingSymbol = await batchMulticallCallWithRetry(ChainId.MAINNET, {
|
77
|
+
calls: callsCollatUnderlyingSymbol,
|
78
|
+
});
|
79
|
+
vaults = vaults.concat((await Promise.all(decodedVaults.map(async (decodedVault, index) => {
|
80
|
+
const collatArray = EulerVaultLensInterface.decodeFunctionResult("getRecognizedCollateralsLTVInfo", resCollat[index].returnData)[0];
|
81
|
+
const collaterals = [];
|
82
|
+
for (const [_index, collat] of collatArray.entries()) {
|
83
|
+
const symbolUnderlying = ERC20Interface.decodeFunctionResult("symbol", resCollatUnderlyingSymbol[_index].returnData)[0];
|
84
|
+
collaterals.push({
|
85
|
+
address: collat.collateral,
|
86
|
+
symbolCollateral: EulerEVKInterface.decodeFunctionResult("symbol", resCollatUnderlying[2 * _index + 1].returnData)[0],
|
87
|
+
symbolUnderlying,
|
88
|
+
borrowLTV: collat.borrowLTV.toString(),
|
89
|
+
nameCollateral: (await fetchEulerVaultName(collat.collateral, chainId)) ?? symbolUnderlying,
|
90
|
+
});
|
91
|
+
}
|
92
|
+
return { ...decodedVault, collaterals };
|
93
|
+
}))));
|
94
|
+
}
|
95
|
+
catch (e) {
|
96
|
+
log.error(`issue when fetching vaults on ${chainId}`, e);
|
82
97
|
}
|
83
|
-
|
84
|
-
})));
|
98
|
+
}
|
85
99
|
return vaults;
|
86
100
|
}
|
87
101
|
export const getEulerV2VaultsWithCache = async () => await Redis.getOrSet("EulerV2Vaults", getEulerV2Vaults);
|