def _estimate_gas(self, master_copy: str, initializer: bytes, funder: str, payment_token: str) -> int: """ Gas estimation done using web3 and calling the node Payment cannot be estimated, as no ether is in the address. So we add some gas later. :param master_copy: Master Copy of Gnosis Safe already deployed :param initializer: Data initializer to send to GnosisSafe setup method :param funder: Address that should get the payment (if payment set) :param payment_token: Address if a token is used. If not set, 0x0 will be ether :return: Total gas estimation """ # Estimate the contract deployment. We cannot estimate the refunding, as the safe address has not any fund gas: int = self._build_proxy_contract_creation_constructor( master_copy, initializer, funder, payment_token, 0).estimateGas() # We estimate the refund as a new tx if payment_token == NULL_ADDRESS: # Same cost to send 1 ether than 1000 gas += self.w3.eth.estimate_gas({'to': funder, 'value': 1}) else: # Top should be around 52000 when storage is needed (funder no previous owner of token), # we use value 1 as we are simulating an internal call, and in that calls you don't pay for the data. # If it was a new tx sending 5000 tokens would be more expensive than sending 1 because of data costs try: gas += get_erc20_contract(self.w3, payment_token).functions.transfer( funder, 1).estimateGas( {'from': payment_token}) except ValueError as exc: if 'transfer amount exceeds balance' in str(exc): return 70000 raise InvalidERC20Token from exc return gas
def __init__(self): super().__init__() compound_contracts = [ self.dummy_w3.eth.contract(abi=ctoken_abi) # self.dummy_w3.eth.contract(abi=comptroller_abi)] ] exchanges = [ get_uniswap_exchange_contract(self.dummy_w3), get_kyber_network_proxy_contract(self.dummy_w3), self.dummy_w3.eth.contract(abi=gnosis_protocol_abi) ] sight_contracts = [ self.dummy_w3.eth.contract(abi=abi) for abi in (conditional_token_abi, market_maker_abi, market_maker_factory_abi) ] erc_contracts = [ get_erc721_contract(self.dummy_w3), get_erc20_contract(self.dummy_w3) ] self.multisend_contracts = [get_multi_send_contract(self.dummy_w3)] # Order is important. If signature is the same (e.g. renaming of `baseGas`) last elements in the list # will take preference self.supported_contracts = (compound_contracts + exchanges + sight_contracts + erc_contracts + self.multisend_contracts + self.supported_contracts)
def __init__(self): super().__init__() compound_contracts = [ self.dummy_w3.eth.contract(abi=ctoken_abi), self.dummy_w3.eth.contract(abi=comptroller_abi), ] aave_abis = [aave_a_token, aave_lending_pool, aave_lending_pool_addresses_provider, aave_lending_pool_core] aave_contracts = [self.dummy_w3.eth.contract(abi=abi) for abi in aave_abis] idle_abis = [idle_token_v3] idle_contracts = [self.dummy_w3.eth.contract(abi=abi) for abi in idle_abis] request_abis = [request_erc20_proxy, request_ethereum_proxy] request_contracts = [self.dummy_w3.eth.contract(abi=abi) for abi in request_abis] sablier_abis = [sablier_ctoken_manager, sablier_payroll, sablier_abi] sablier_contracts = [self.dummy_w3.eth.contract(abi=abi) for abi in sablier_abis] exchanges = [get_uniswap_exchange_contract(self.dummy_w3), get_kyber_network_proxy_contract(self.dummy_w3), self.dummy_w3.eth.contract(abi=gnosis_protocol_abi)] sight_contracts = [self.dummy_w3.eth.contract(abi=abi) for abi in (conditional_token_abi, market_maker_abi, market_maker_factory_abi)] erc_contracts = [get_erc721_contract(self.dummy_w3), get_erc20_contract(self.dummy_w3)] self.multisend_contracts = [get_multi_send_contract(self.dummy_w3)] # Order is important. If signature is the same (e.g. renaming of `baseGas`) last elements in the list # will take preference self.supported_contracts = (aave_contracts + idle_contracts + request_contracts + sablier_contracts + compound_contracts + exchanges + sight_contracts + erc_contracts + self.multisend_contracts + self.supported_contracts)
def __init__(self): #TODO Refactor this using inheritance self.dummy_w3 = Web3() exchanges = [ get_uniswap_exchange_contract(self.dummy_w3), self.dummy_w3.eth.contract(abi=gnosis_protocol_abi) ] sight_contracts = [ self.dummy_w3.eth.contract(abi=abi) for abi in (conditional_token_abi, market_maker_abi, market_maker_factory_abi) ] erc_contracts = [ get_erc721_contract(self.dummy_w3), get_erc20_contract(self.dummy_w3) ] safe_contracts = [ get_safe_V0_0_1_contract(self.dummy_w3), get_safe_V1_0_0_contract(self.dummy_w3), get_safe_contract(self.dummy_w3) ] # Order is important. If signature is the same (e.g. renaming of `baseGas`) last elements in the list # will take preference self.supported_contracts = exchanges + sight_contracts + erc_contracts + safe_contracts # Web3 generates possible selectors every time. We cache that and use a dict to do a fast check # Store selectors with abi self.supported_fn_selectors: Dict[bytes, ContractFunction] = {} for supported_contract in self.supported_contracts: self.supported_fn_selectors.update( self._generate_selectors_with_abis_from_contract( supported_contract))
def send_token(w3, account, to, amount_to_send, token_address, nonce=None): erc20_contract = get_erc20_contract(w3, token_address) nonce = nonce if nonce is not None else w3.eth.getTransactionCount(account.address, 'pending') tx = erc20_contract.functions.transfer(to, amount_to_send).buildTransaction({'from': account.address, 'nonce': nonce}) signed_tx = w3.eth.account.signTransaction(tx, private_key=account.privateKey) return w3.eth.sendRawTransaction(signed_tx.rawTransaction)
def get_supported_abis(self) -> List[ABI]: supported_abis = super().get_supported_abis() aave_contracts = [ aave_a_token, aave_lending_pool, aave_lending_pool_addresses_provider, aave_lending_pool_core ] initializable_admin_upgradeability_proxy_contracts = [ initializable_admin_upgradeability_proxy_abi ] balancer_contracts = [balancer_bactions, balancer_exchange_proxy] chainlink_contracts = [chainlink_token_abi] compound_contracts = [ctoken_abi, comptroller_abi] idle_contracts = [idle_token_v3] maker_dao_contracts = maker_dao_abis open_zeppelin_contracts = [ open_zeppelin_admin_upgradeability_proxy, open_zeppelin_proxy_admin ] request_contracts = [ request_erc20_proxy, request_erc20_swap_to_pay, request_ethereum_proxy ] sablier_contracts = [ sablier_ctoken_manager, sablier_payroll, sablier_abi ] snapshot_contracts = [snapshot_delegate_registry_abi] exchanges = [ get_uniswap_exchange_contract(self.dummy_w3).abi, get_kyber_network_proxy_contract(self.dummy_w3).abi ] sight_contracts = [ conditional_token_abi, market_maker_abi, market_maker_factory_abi ] gnosis_protocol = [ gnosis_protocol_abi, fleet_factory_deterministic_abi, fleet_factory_abi ] gnosis_safe = [gnosis_safe_allowance_module_abi] erc_contracts = [ get_erc721_contract(self.dummy_w3).abi, get_erc20_contract(self.dummy_w3).abi ] timelock_contracts = [timelock_abi] # Order is important. If signature is the same (e.g. renaming of `baseGas`) last elements in the list # will take preference return (timelock_contracts + initializable_admin_upgradeability_proxy_contracts + aave_contracts + balancer_contracts + chainlink_contracts + idle_contracts + maker_dao_contracts + request_contracts + sablier_contracts + snapshot_contracts + open_zeppelin_contracts + compound_contracts + exchanges + sight_contracts + gnosis_protocol + gnosis_safe + erc_contracts + self._get_multisend_abis() + supported_abis)
def send_erc20(self, to: str, token_address: str, amount: int, **kwargs) -> bool: transaction = get_erc20_contract(self.ethereum_client.w3, token_address).functions.transfer( to, amount).buildTransaction({ 'from': self.address, 'gas': 0, 'gasPrice': 0 }) return self.send_custom(token_address, 0, HexBytes(transaction['data']), **kwargs)
def send_erc20(self, to: str, token_address: str, amount: int, **kwargs) -> bool: transaction = (get_erc20_contract(self.ethereum_client.w3, token_address).functions.transfer( to, amount).buildTransaction({ "from": self.address, "gas": 0, "gasPrice": 0 })) return self.send_custom(token_address, 0, HexBytes(transaction["data"]), **kwargs)
def get_supported_contracts(self) -> List[Type[Contract]]: supported_contracts = super().get_supported_contracts() aave_contracts = [ self.dummy_w3.eth.contract(abi=abi) for abi in (aave_a_token, aave_lending_pool, aave_lending_pool_addresses_provider, aave_lending_pool_core) ] initializable_admin_upgradeability_proxy_contracts = [ self.dummy_w3.eth.contract( abi=initializable_admin_upgradeability_proxy_abi) ] balancer_contracts = [ self.dummy_w3.eth.contract(abi=abi) for abi in (balancer_bactions, balancer_exchange_proxy) ] chainlink_contracts = [ self.dummy_w3.eth.contract(abi=abi) for abi in (chainlink_token_abi, ) ] compound_contracts = [ self.dummy_w3.eth.contract(abi=abi) for abi in (ctoken_abi, comptroller_abi) ] idle_contracts = [ self.dummy_w3.eth.contract(abi=abi) for abi in (idle_token_v3, ) ] maker_dao_contracts = [ self.dummy_w3.eth.contract(abi=abi) for abi in maker_dao_abis ] open_zeppelin_contracts = [ self.dummy_w3.eth.contract(abi=abi) for abi in (open_zeppelin_admin_upgradeability_proxy, open_zeppelin_proxy_admin) ] request_contracts = [ self.dummy_w3.eth.contract(abi=abi) for abi in (request_erc20_proxy, request_erc20_swap_to_pay, request_ethereum_proxy) ] sablier_contracts = [ self.dummy_w3.eth.contract(abi=abi) for abi in (sablier_ctoken_manager, sablier_payroll, sablier_abi) ] snapshot_contracts = [ self.dummy_w3.eth.contract(abi=abi) for abi in (snapshot_delegate_registry_abi, ) ] exchanges = [ get_uniswap_exchange_contract(self.dummy_w3), get_kyber_network_proxy_contract(self.dummy_w3) ] sight_contracts = [ self.dummy_w3.eth.contract(abi=abi) for abi in (conditional_token_abi, market_maker_abi, market_maker_factory_abi) ] gnosis_protocol = [ self.dummy_w3.eth.contract(abi=abi) for abi in (gnosis_protocol_abi, fleet_factory_deterministic_abi, fleet_factory_abi) ] gnosis_safe = [ self.dummy_w3.eth.contract(abi=abi) for abi in (allowance_module_abi, ) ] erc_contracts = [ get_erc721_contract(self.dummy_w3), get_erc20_contract(self.dummy_w3) ] test_contracts = [ self.dummy_w3.eth.contract(abi=decoging_test_abi) ] # https://rinkeby.etherscan.io/address/0x479adf13cc2e1844451f71dcf0bf5194df53b14b#code timelock_contracts = [self.dummy_w3.eth.contract(abi=timelock_abi)] # Order is important. If signature is the same (e.g. renaming of `baseGas`) last elements in the list # will take preference return (test_contracts + timelock_contracts + initializable_admin_upgradeability_proxy_contracts + aave_contracts + balancer_contracts + chainlink_contracts + idle_contracts + maker_dao_contracts + request_contracts + sablier_contracts + snapshot_contracts + open_zeppelin_contracts + compound_contracts + exchanges + sight_contracts + gnosis_protocol + gnosis_safe + erc_contracts + self.multisend_contracts + supported_contracts)
def send_erc20(self, address: str, token_address: str, value: int) -> bool: transaction = get_erc20_contract(self.ethereum_client.w3, token_address).functions.transfer( address, value ).buildTransaction({'from': self.address, 'gas': 0, 'gasPrice': 0}) return self.execute_safe_transaction(token_address, 0, transaction['data'])