Skip to content

Commit 7a1bb08

Browse files
committed
v0.1.7, better out of gas handling and less verbose logs.
1 parent 5885e7c commit 7a1bb08

File tree

2 files changed

+180
-184
lines changed

2 files changed

+180
-184
lines changed

IceCreamSwapWeb3/Multicall.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ class MultiCall:
3131
CALLER_ADDRESS = "0x0000000000000000000000000000000000000123"
3232

3333
MULTICALL_DEPLOYMENTS: dict[int, str] = {
34-
56: "0xE396FfB7aa3123E3D742e50Ad409d212f87ADfA6",
35-
1116: "0xf7bfc56C50e544ba035d0b27978aF2f072b096f7",
36-
40: "0x4E1F64D55cD51E8D8D2125A5c1Fa613E78921C51",
34+
56: "0x06EF84EE8E60fA7d95277E8232Dd3aEEb1377e17",
35+
1116: "0x66BF74f6Afe41fd10a5343B39Dae017EF9CceF1b",
36+
40: "0x84C2fb5A4F7219688AF475e74b2ac189966Cc9ba",
3737
}
3838

3939
@classmethod
@@ -124,24 +124,27 @@ def _inner_call(
124124
multicall_call=multicall_call,
125125
retry=len(calls_with_calldata) == 1
126126
)
127-
except Exception as e:
127+
except Exception:
128128
if len(calls_with_calldata) == 1:
129-
print(f"Multicall with single call got Exception '{repr(e)}', last retry")
130-
sleep(1)
131129
try:
132130
raw_returns, gas_usages = self._call_multicall(
133131
multicall_call=multicall_call,
134132
retry=len(calls_with_calldata) == 1
135133
)
136134
except Exception as e:
137-
print(f"Multicall with single call got Exception '{repr(e)}', returning Exception")
138135
raw_returns = [e]
139136
gas_usages = [None]
140137
else:
141-
print(f"Multicall got Exception '{repr(e)}', splitting and retrying")
142138
left_results, left_gas_usages = self._inner_call(**kwargs, calls_with_calldata=calls_with_calldata[:len(calls_with_calldata) // 2])
143139
right_results, right_gas_usages = self._inner_call(**kwargs, calls_with_calldata=calls_with_calldata[len(calls_with_calldata) // 2:])
144140
return left_results + right_results, left_gas_usages + right_gas_usages
141+
else:
142+
if len(raw_returns) != len(calls_with_calldata) and len(raw_returns) > 1:
143+
# multicall stopped in the middle due to running out of gas.
144+
# better remove the last result.
145+
raw_returns = raw_returns[:-1]
146+
gas_usages = gas_usages[:-1]
147+
assert len(raw_returns) == len(gas_usages)
145148
results = self.decode_contract_function_results(raw_returns=raw_returns, contract_functions=[call for call, _ in calls_with_calldata])
146149
if len(results) == len(calls_with_calldata):
147150
return results, gas_usages
@@ -354,9 +357,7 @@ def _call_multicall(self, multicall_call: ContractConstructor | ContractFunction
354357
"data": calldata,
355358
"no_retry": not retry,
356359
})
357-
_, multicall_result, completed_calls = eth_abi.decode(get_abi_output_types(multicall_call.abi), raw_response)
358-
359-
multicall_result = multicall_result[:completed_calls]
360+
_, multicall_result = eth_abi.decode(get_abi_output_types(multicall_call.abi), raw_response)
360361

361362
if len(multicall_result) > 0 and self.undeployed_contract_constructor is not None:
362363
# remove first call result as that's the deployment of the undeployed contract

0 commit comments

Comments
 (0)