Skip to content

Commit c357e35

Browse files
committed
v0.1.46 added block identifier support to Multicall
1 parent 7a1ad39 commit c357e35

File tree

2 files changed

+25
-9
lines changed

2 files changed

+25
-9
lines changed

IceCreamSwapWeb3/Multicall.py

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from typing import Optional
44

55
import eth_abi
6+
from eth_typing import BlockIdentifier
67
from eth_utils import to_bytes
78
from eth_utils.abi import get_abi_output_types, get_abi_input_types
89
from web3.contract.contract import ContractFunction, ContractConstructor
@@ -81,20 +82,23 @@ def call(
8182
self,
8283
use_revert: Optional[bool] = None,
8384
batch_size: int = 1_000,
84-
state_override: Optional[StateOverride] = None
85+
state_override: Optional[StateOverride] = None,
86+
block_identifier: Optional[BlockIdentifier] = None
8587
):
8688
results, _ = self.call_with_gas(
8789
use_revert=use_revert,
8890
batch_size=batch_size,
89-
state_override=state_override
91+
state_override=state_override,
92+
block_identifier=block_identifier
9093
)
9194
return results
9295

9396
def call_with_gas(
9497
self,
9598
use_revert: Optional[bool] = None,
9699
batch_size: int = 1_000,
97-
state_override: Optional[StateOverride] = None
100+
state_override: Optional[StateOverride] = None,
101+
block_identifier: Optional[BlockIdentifier] = None
98102
):
99103
if state_override is not None:
100104
assert self.w3.overwrites_available
@@ -111,6 +115,7 @@ def call_with_gas(
111115
batch_size=batch_size,
112116
state_overwrites=state_overwrites,
113117
global_state_override=state_override,
118+
block_identifier=block_identifier,
114119
)
115120

116121
def _inner_call(
@@ -120,6 +125,7 @@ def _inner_call(
120125
batch_size: int,
121126
state_overwrites: list[StateOverride | None],
122127
global_state_override: StateOverride | None = None,
128+
block_identifier: Optional[BlockIdentifier] = None
123129
) -> tuple[list[Exception | tuple[any, ...]], list[int]]:
124130
assert len(calls_with_calldata) == len(state_overwrites)
125131
if len(calls_with_calldata) == 0:
@@ -128,6 +134,7 @@ def _inner_call(
128134
use_revert=use_revert,
129135
batch_size=batch_size,
130136
global_state_override=global_state_override,
137+
block_identifier=block_identifier
131138
)
132139
# make sure calls are not bigger than batch_size
133140
if len(calls_with_calldata) > batch_size:
@@ -162,7 +169,8 @@ def _inner_call(
162169
multicall_call=multicall_call,
163170
use_revert=use_revert,
164171
retry=False,
165-
state_override=state_override
172+
state_override=state_override,
173+
block_identifier=block_identifier
166174
)
167175
except Exception as e:
168176
if len(calls_with_calldata) == 1:
@@ -171,7 +179,8 @@ def _inner_call(
171179
multicall_call=multicall_call,
172180
use_revert=use_revert,
173181
retry=True,
174-
state_override=state_override
182+
state_override=state_override,
183+
block_identifier=block_identifier
175184
)
176185
except Exception as e:
177186
raw_returns = [e]
@@ -417,7 +426,8 @@ def _call_multicall(
417426
multicall_call: ContractConstructor | ContractFunction,
418427
use_revert: bool,
419428
retry: bool = False,
420-
state_override: Optional[StateOverride] = None
429+
state_override: Optional[StateOverride] = None,
430+
block_identifier: Optional[BlockIdentifier] = None
421431
):
422432
# call transaction
423433
try:
@@ -427,7 +437,10 @@ def _call_multicall(
427437
"nonce": 0,
428438
"data": multicall_call.data_in_transaction,
429439
"no_retry": not retry,
430-
}, state_override=state_override)
440+
},
441+
state_override=state_override,
442+
block_identifier=block_identifier
443+
)
431444
else:
432445
assert isinstance(multicall_call, ContractFunction)
433446
# manually encoding and decoding call because web3.py is sooooo slow...
@@ -446,7 +459,10 @@ def _call_multicall(
446459
"nonce": 0,
447460
"data": calldata,
448461
"no_retry": not retry,
449-
}, state_override=state_override)
462+
},
463+
state_override=state_override,
464+
block_identifier=block_identifier
465+
)
450466
_, multicall_result = eth_abi.decode(get_abi_output_types(multicall_call.abi), raw_response)
451467

452468
if len(multicall_result) > 0 and self.undeployed_contract_constructor is not None:

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from setuptools import setup, find_packages
22

3-
VERSION = '0.1.45'
3+
VERSION = '0.1.46'
44
DESCRIPTION = 'IceCreamSwap Web3.py wrapper'
55
LONG_DESCRIPTION = 'IceCreamSwap Web3.py wrapper with automatic retries, multicall and other advanced functionality'
66

0 commit comments

Comments
 (0)