Skip to content

Commit

Permalink
Multicall3 (#86)
Browse files Browse the repository at this point in the history
* feat: support multicall3

* fix: AttributeError
  • Loading branch information
BobTheBuidler authored Aug 30, 2023
1 parent 6518e1b commit c5f32c4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
22 changes: 18 additions & 4 deletions dank_mids/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
from dank_mids.types import BlockId, ChainId, PartialRequest, RawResponse
from dank_mids.uid import UIDGenerator, _AlertingRLock

try:
from multicall.constants import MULTICALL3_ADDRESSES
except ImportError:
MULTICALL3_ADDRESSES = {}

logger = logging.getLogger(__name__)

instances: DefaultDict[ChainId, List["DankMiddlewareController"]] = defaultdict(list)
Expand Down Expand Up @@ -64,11 +69,20 @@ def __init__(self, w3: Web3) -> None:

multicall = MULTICALL_ADDRESSES.get(self.chain_id)
multicall2 = MULTICALL2_ADDRESSES.get(self.chain_id)
if multicall2 is None:
multicall3 = MULTICALL3_ADDRESSES.get(self.chain_id)
if multicall2 is None and multicall3 is None:
raise NotImplementedError("Dank Mids currently does not support this network.\nTo add support, you just need to submit a PR adding the appropriate multicall contract addresses to this file:\nhttps://github.com/banteg/multicall.py/blob/master/multicall/constants.py")
self.multicall2 = to_checksum_address(multicall2)
self.no_multicall = {self.multicall2} if multicall is None else {self.multicall2, to_checksum_address(multicall)}

elif multicall2 and multicall3:
self.multicall = to_checksum_address(multicall3)
self.no_multicall = {self.multicall, to_checksum_address(multicall2)}
else:
self.multicall = to_checksum_address(multicall3 if multicall3 else multicall2)
self.no_multicall = {self.multicall}
if multicall:
self.no_multicall.add(to_checksum_address(multicall))

self.multicall = to_checksum_address(multicall2 if multicall2 else multicall3)

self.method_semaphores = MethodSemaphores(self)
self.batcher = NotSoBrightBatcher()

Expand Down
2 changes: 1 addition & 1 deletion dank_mids/requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ def calldata(self) -> str:

@property
def target(self) -> ChecksumAddress:
return self.controller.multicall2
return self.controller.multicall

@property
def params(self) -> JsonrpcParams:
Expand Down

0 comments on commit c5f32c4

Please sign in to comment.