Skip to content

Commit

Permalink
Add method to deploy Safe contract V1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Uxio0 committed Nov 20, 2019
1 parent 86bff71 commit a1b122d
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 22 deletions.
7 changes: 4 additions & 3 deletions config/settings/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
SAFE_FUNDER_MAX_ETH = 0.1
SAFE_FUNDING_CONFIRMATIONS = 0
SAFE_GAS_PRICE = 1
SAFE_CONTRACT_ADDRESS = '0x8942595A2dC5181Df0465AF0D7be08c8f23C93af'
SAFE_OLD_CONTRACT_ADDRESS = '0x8942595A2dC5181Df0465AF0D7be08c8f23C93af'
SAFE_PROXY_FACTORY_ADDRESS = '0xbAd4568548ce9DB97463B24c0807F6503e569aBe'
SAFE_CONTRACT_ADDRESS = '0xaE32496491b53841efb51829d6f886387708F99B'
SAFE_V1_0_0_CONTRACT_ADDRESS = '0xb6029EA3B2c51D09a50B53CA8012FeEB05bDa35A'
SAFE_V0_0_1_CONTRACT_ADDRESS = '0x8942595A2dC5181Df0465AF0D7be08c8f23C93af'
SAFE_PROXY_FACTORY_ADDRESS = '0x50e55Af101C777bA7A1d560a774A82eF002ced9F'
SAFE_VALID_CONTRACT_ADDRESSES = [SAFE_CONTRACT_ADDRESS]
30 changes: 29 additions & 1 deletion gnosis/safe/safe.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

from gnosis.eth.constants import NULL_ADDRESS
from gnosis.eth.contracts import (get_delegate_constructor_proxy_contract,
get_safe_contract, get_safe_V0_0_1_contract)
get_safe_contract, get_safe_V0_0_1_contract, get_safe_V1_0_0_contract)
from gnosis.eth.ethereum_client import EthereumClient, EthereumTxSent
from gnosis.eth.utils import get_eth_address_with_key
from gnosis.safe.proxy_factory import ProxyFactory
Expand Down Expand Up @@ -119,6 +119,34 @@ def deploy_master_contract(ethereum_client: EthereumClient, deployer_account: Lo
deployer_account.address)
return ethereum_tx_sent

@staticmethod
def deploy_master_contract_v1_0_0(ethereum_client: EthereumClient, deployer_account: LocalAccount) -> EthereumTxSent:
"""
Deploy master contract. Takes deployer_account (if unlocked in the node) or the deployer private key
:param ethereum_client:
:param deployer_account: Ethereum account
:return: deployed contract address
"""

safe_contract = get_safe_V1_0_0_contract(ethereum_client.w3)
constructor_data = safe_contract.constructor().buildTransaction({'gas': 0})['data']
initializer_data = safe_contract.functions.setup(
# We use 2 owners that nobody controls for the master copy
["0x0000000000000000000000000000000000000002", "0x0000000000000000000000000000000000000003"],
2, # Threshold. Maximum security
NULL_ADDRESS, # Address for optional DELEGATE CALL
b'', # Data for optional DELEGATE CALL
NULL_ADDRESS, # Payment token
0, # Payment
NULL_ADDRESS # Refund receiver
).buildTransaction({'to': NULL_ADDRESS})['data']

ethereum_tx_sent = ethereum_client.deploy_and_initialize_contract(deployer_account, constructor_data,
initializer_data)
logger.info("Deployed and initialized Safe Master Contract=%s by %s", ethereum_tx_sent.contract_address,
deployer_account.address)
return ethereum_tx_sent

@staticmethod
def deploy_old_master_contract(ethereum_client: EthereumClient, deployer_account: LocalAccount) -> EthereumTxSent:
"""
Expand Down
16 changes: 11 additions & 5 deletions gnosis/safe/tests/safe_test_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from gnosis.eth.contracts import (get_multi_send_contract,
get_proxy_factory_contract,
get_safe_contract, get_safe_V0_0_1_contract)
get_safe_contract, get_safe_V1_0_0_contract)
from gnosis.eth.tests.ethereum_test_case import EthereumTestCaseMixin
from gnosis.eth.utils import get_eth_address_with_key
from gnosis.safe import Safe
Expand All @@ -23,6 +23,7 @@
contract_addresses = {
'safe': Safe.deploy_master_contract,
'safe_V0_0_1': Safe.deploy_old_master_contract,
'safe_V1_0_0': Safe.deploy_master_contract_v1_0_0,
'proxy_factory': ProxyFactory.deploy_proxy_factory_contract,
'multi_send': MultiSend.deploy_contract,
}
Expand All @@ -39,13 +40,18 @@ def setUpTestData(cls):

settings.SAFE_CONTRACT_ADDRESS = contract_addresses['safe']
settings.SAFE_MULTISEND_ADDRESS = contract_addresses['multi_send']
settings.SAFE_OLD_CONTRACT_ADDRESS = contract_addresses['safe_V0_0_1']
settings.SAFE_V1_0_0_CONTRACT_ADDRESS = contract_addresses['safe_V1_0_0']
settings.SAFE_V0_0_1_CONTRACT_ADDRESS = contract_addresses['safe_V0_0_1']
settings.SAFE_PROXY_FACTORY_ADDRESS = contract_addresses['proxy_factory']
settings.SAFE_VALID_CONTRACT_ADDRESSES = {settings.SAFE_CONTRACT_ADDRESS, settings.SAFE_OLD_CONTRACT_ADDRESS}
settings.SAFE_VALID_CONTRAC1_ADDRESSES = {settings.SAFE_CONTRACT_ADDRESS,
settings.SAFE_V0_0_1_CONTRACT_ADDRESS,
settings.SAFE_V1_0_0_CONTRACT_ADDRESS}
cls.safe_contract_address = contract_addresses['safe']
cls.safe_contract = get_safe_contract(cls.w3, cls.safe_contract_address)
cls.safe_old_contract_address = contract_addresses['safe_V0_0_1']
cls.safe_old_contract = get_safe_V0_0_1_contract(cls.w3, cls.safe_old_contract_address)
cls.safe_contract_V1_0_0_address = contract_addresses['safe_V1_0_0']
cls.safe_contract_V1_0_0 = get_safe_V1_0_0_contract(cls.w3, cls.safe_contract_V1_0_0_address)
cls.safe_contract_V0_0_1_address = contract_addresses['safe_V0_0_1']
cls.safe_contract_V0_0_1 = get_safe_V1_0_0_contract(cls.w3, cls.safe_contract_V0_0_1_address)
cls.proxy_factory_contract_address = contract_addresses['proxy_factory']
cls.proxy_factory_contract = get_proxy_factory_contract(cls.w3, cls.proxy_factory_contract_address)
cls.proxy_factory = ProxyFactory(cls.proxy_factory_contract_address, cls.ethereum_client)
Expand Down
2 changes: 1 addition & 1 deletion gnosis/safe/tests/test_proxy_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def test_deploy_proxy_contract(self):
owners = [Account.create().address for _ in range(2)]
threshold = 2
payment_token = None
safe_creation_tx = Safe.build_safe_creation_tx(self.ethereum_client, self.safe_old_contract_address,
safe_creation_tx = Safe.build_safe_creation_tx(self.ethereum_client, self.safe_contract_V0_0_1_address,
s, owners, threshold, self.gas_price, payment_token,
payment_receiver=self.ethereum_test_account.address)
# Send ether for safe deploying costs
Expand Down
2 changes: 1 addition & 1 deletion gnosis/safe/tests/test_safe.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def test_estimate_safe_creation(self):
number_owners = 4
gas_price = self.gas_price
payment_token = NULL_ADDRESS
safe_creation_estimate = Safe.estimate_safe_creation(self.ethereum_client, self.safe_old_contract_address,
safe_creation_estimate = Safe.estimate_safe_creation(self.ethereum_client, self.safe_contract_V0_0_1_address,
number_owners, gas_price, payment_token)
self.assertGreater(safe_creation_estimate.gas_price, 0)
self.assertGreater(safe_creation_estimate.gas, 0)
Expand Down
22 changes: 11 additions & 11 deletions gnosis/safe/tests/test_safe_creation_tx.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def test_safe_creation_tx_builder(self):
owners=owners,
threshold=threshold,
signature_s=s,
master_copy=self.safe_old_contract_address,
master_copy=self.safe_contract_V0_0_1_address,
gas_price=gas_price,
funder=NULL_ADDRESS)

Expand Down Expand Up @@ -73,7 +73,7 @@ def test_safe_creation_tx_builder_with_not_enough_funds(self):
owners=owners,
threshold=threshold,
signature_s=s,
master_copy=self.safe_old_contract_address,
master_copy=self.safe_contract_V0_0_1_address,
gas_price=gas_price,
funder=NULL_ADDRESS)

Expand Down Expand Up @@ -103,7 +103,7 @@ def test_safe_creation_tx_builder_with_payment(self):
owners=owners,
threshold=threshold,
signature_s=s,
master_copy=self.safe_old_contract_address,
master_copy=self.safe_contract_V0_0_1_address,
gas_price=gas_price,
funder=funder_account.address)

Expand Down Expand Up @@ -176,7 +176,7 @@ def test_safe_creation_tx_builder_with_token_payment(self):
owners=owners,
threshold=threshold,
signature_s=s,
master_copy=self.safe_old_contract_address,
master_copy=self.safe_contract_V0_0_1_address,
gas_price=gas_price,
payment_token=erc20_contract.address,
funder=funder)
Expand Down Expand Up @@ -222,7 +222,7 @@ def test_safe_creation_tx_builder_with_token_payment(self):
owners=owners,
threshold=threshold,
signature_s=s,
master_copy=self.safe_old_contract_address,
master_copy=self.safe_contract_V0_0_1_address,
gas_price=gas_price,
payment_token=erc20_contract.address,
payment_token_eth_value=1.0,
Expand All @@ -234,7 +234,7 @@ def test_safe_creation_tx_builder_with_token_payment(self):
owners=owners,
threshold=threshold,
signature_s=s,
master_copy=self.safe_old_contract_address,
master_copy=self.safe_contract_V0_0_1_address,
gas_price=gas_price,
payment_token=erc20_contract.address,
payment_token_eth_value=1.0,
Expand All @@ -246,7 +246,7 @@ def test_safe_creation_tx_builder_with_token_payment(self):
owners=owners,
threshold=threshold,
signature_s=s,
master_copy=self.safe_old_contract_address,
master_copy=self.safe_contract_V0_0_1_address,
gas_price=gas_price,
payment_token=erc20_contract.address,
payment_token_eth_value=1.1,
Expand All @@ -258,7 +258,7 @@ def test_safe_creation_tx_builder_with_token_payment(self):
owners=owners,
threshold=threshold,
signature_s=s,
master_copy=self.safe_old_contract_address,
master_copy=self.safe_contract_V0_0_1_address,
gas_price=gas_price,
payment_token=erc20_contract.address,
payment_token_eth_value=0.1,
Expand All @@ -281,7 +281,7 @@ def test_safe_creation_tx_builder_with_fixed_cost(self):
owners=owners,
threshold=threshold,
signature_s=s,
master_copy=self.safe_old_contract_address,
master_copy=self.safe_contract_V0_0_1_address,
gas_price=gas_price,
payment_token=None,
funder=funder_account.address,
Expand Down Expand Up @@ -342,7 +342,7 @@ def test_safe_gas_with_multiple_owners(self):
owners=owners,
threshold=threshold,
signature_s=s,
master_copy=self.safe_old_contract_address,
master_copy=self.safe_contract_V0_0_1_address,
gas_price=gas_price,
funder=None)

Expand Down Expand Up @@ -374,7 +374,7 @@ def test_w3_same_tx_pyethereum(self):
owners=owners,
threshold=threshold,
signature_s=s,
master_copy=self.safe_old_contract_address,
master_copy=self.safe_contract_V0_0_1_address,
gas_price=gas_price,
funder=funder_account.address)

Expand Down

0 comments on commit a1b122d

Please sign in to comment.