Skip to content

Commit

Permalink
Merge e2f4267 into 4ffd701
Browse files Browse the repository at this point in the history
  • Loading branch information
Uxio0 committed Aug 4, 2022
2 parents 4ffd701 + e2f4267 commit bd7b013
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
25 changes: 21 additions & 4 deletions gnosis/safe/multi_send.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,31 +165,48 @@ def _decode_multisend_old_transaction(
class MultiSend:
dummy_w3 = Web3()
MULTISEND_ADDRESSES = (
"0xA238CBeb142c10Ef7Ad8442C6D1f9E89e07e7761",
"0x998739BFdAAdde7C933B942a68053933098f9EDa",
"0xA238CBeb142c10Ef7Ad8442C6D1f9E89e07e7761", # MultiSend v1.3.0
"0x998739BFdAAdde7C933B942a68053933098f9EDa", # MultiSend v1.3.0 (EIP-155)
)
MULTISEND_CALL_ONLY_ADDRESSES = (
"0x40A2aCCbd92BCA938b02010E17A5b8929b49130D", # MultiSend Call Only v1.3.0
"0xA1dabEF33b3B82c7814B6D82A79e50F4AC44102B", # MultiSend Call Only v1.3.0 (EIP-155)
)

def __init__(
self,
ethereum_client: Optional[EthereumClient] = None,
address: Optional[ChecksumAddress] = None,
call_only: bool = True,
):
"""
:param ethereum_client: Required for detecting the address in the network.
:param address: If not provided, will try to detect it from the hardcoded addresses using `ethereum_client`.
:param call_only: If `True` use `call only` MultiSend, otherwise use regular one.
Only if `address` not provided
"""

self.address = address
self.ethereum_client = ethereum_client
self.call_only = call_only
addresses = (
self.MULTISEND_CALL_ONLY_ADDRESSES
if call_only
else self.MULTISEND_ADDRESSES
)

if address:
assert fast_is_checksum_address(address), (
"%s proxy factory address not valid" % address
)
elif ethereum_client:
# Try to detect MultiSend address if not provided
for address in self.MULTISEND_ADDRESSES:
for address in addresses:
if ethereum_client.is_contract(address):
self.address = address
break
else:
self.address = self.MULTISEND_ADDRESSES[0]
self.address = addresses[0]

if not self.address:
raise ValueError(
Expand Down
12 changes: 10 additions & 2 deletions gnosis/safe/tests/test_multi_send.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,25 @@ def test_multisend_init(self):
MultiSend(self.ethereum_client)

with mock.patch.object(EthereumClient, "is_contract", return_value=True):
multisend = MultiSend(self.ethereum_client)
multisend = MultiSend(self.ethereum_client, call_only=False)
self.assertEqual(multisend.address, multisend.MULTISEND_ADDRESSES[0])

multisend = MultiSend(self.ethereum_client)
self.assertEqual(
multisend.address, multisend.MULTISEND_CALL_ONLY_ADDRESSES[0]
)

random_address = Account.create().address
multisend = MultiSend(self.ethereum_client, address=random_address)
self.assertEqual(multisend.address, random_address)

# Check with no ethereum_client
multisend = MultiSend()
multisend = MultiSend(call_only=False)
self.assertEqual(multisend.address, multisend.MULTISEND_ADDRESSES[0])

multisend = MultiSend()
self.assertEqual(multisend.address, multisend.MULTISEND_CALL_ONLY_ADDRESSES[0])

def test_multi_send_tx_from_bytes(self):
operation = MultiSendOperation.DELEGATE_CALL
address = Account.create().address
Expand Down

0 comments on commit bd7b013

Please sign in to comment.