@defillama/sdk 5.0.161 → 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.
@@ -208,6 +208,9 @@ const DEPLOYMENT_BLOCK = {
208
208
  vechain: 22103870,
209
209
  tac: 1,
210
210
  eventum: 1,
211
+ somnia: 1,
212
+ camp: 1,
213
+ bitci: 1,
211
214
  };
212
215
  async function makeMultiCall(functionABI, calls, chain, block) {
213
216
  if (chain === 'tron')
@@ -308,4 +311,6 @@ const CUSTOM_MULTICALL_ADDRESSES = {
308
311
  'xrplevm': '0xaB3a12b26e72F4D6D9B579aCb5027a0918eF1114',
309
312
  'vechain': '0x8B2fF167683c5e1DFD6717d934B560F20cf9F2a3',
310
313
  'eventum': '0xc7dEfc896E1Dd9D98AEa402d928C78c0FD1dc36C',
314
+ 'somnia': '0x5e44F178E8cF9B2F5409B6f18ce936aB817C5a11',
315
+ 'bitci': '0x777238B119cD07e6849b0817f284532DC0F9F8D9',
311
316
  };
@@ -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;