@defillama/sdk 5.0.163 → 5.0.165

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.
@@ -15,9 +15,7 @@ export declare function getBalances(params: {
15
15
  decimals?: number;
16
16
  chain?: Chain;
17
17
  logArray?: LogArray;
18
+ skipMultiCall?: boolean;
18
19
  }): Promise<{
19
- output: {
20
- target: string;
21
- balance: any;
22
- }[];
20
+ output: any;
23
21
  }>;
@@ -26,6 +26,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.getBalances = exports.getBalance = void 0;
27
27
  const general_1 = require("../general");
28
28
  const Tron = __importStar(require("../abi/tron"));
29
+ const multicall3_1 = require("../abi/multicall3");
30
+ const abi2_1 = require("../abi/abi2");
31
+ const debugLog_1 = require("../util/debugLog");
29
32
  async function getBalance(params) {
30
33
  var _a;
31
34
  if (params.chain === 'tron')
@@ -45,13 +48,36 @@ async function getBalance(params) {
45
48
  }
46
49
  exports.getBalance = getBalance;
47
50
  async function getBalances(params) {
51
+ var _a;
48
52
  if (params.chain === 'tron')
49
53
  return Tron.getBalances(params);
50
- const balances = params.targets.map(async (target) => ({
51
- target,
52
- balance: (0, general_1.handleDecimals)(await (0, general_1.getProvider)(params.chain).getBalance(target, params.block), params.decimals),
53
- }));
54
- const output = await Promise.all(balances);
54
+ let output;
55
+ try {
56
+ const multicallContract = (0, multicall3_1.getMulticallAddress)((_a = params.chain) !== null && _a !== void 0 ? _a : "ethereum", params.block);
57
+ if (!params.skipMultiCall && multicallContract) {
58
+ const multicallResults = await (0, abi2_1.multiCall)({
59
+ calls: params.targets,
60
+ target: multicallContract,
61
+ abi: 'function getEthBalance(address addr) view returns (uint256)',
62
+ chain: params.chain,
63
+ block: params.block,
64
+ });
65
+ output = multicallResults.map((value, i) => ({
66
+ target: params.targets[i],
67
+ balance: (0, general_1.handleDecimals)(value, params.decimals)
68
+ }));
69
+ }
70
+ }
71
+ catch (e) {
72
+ (0, debugLog_1.debugLog)('Multicall failed, falling back to single calls for fetching eth balances', e);
73
+ }
74
+ if (!output) {
75
+ const balances = params.targets.map(async (target) => ({
76
+ target,
77
+ balance: (0, general_1.handleDecimals)(await (0, general_1.getProvider)(params.chain).getBalance(target, params.block), params.decimals),
78
+ }));
79
+ output = await Promise.all(balances);
80
+ }
55
81
  if (params.logArray)
56
82
  params.logArray.push(...params.targets.map((holder, i) => {
57
83
  var _a;