gnosis/safe/safe_create2_tx.py
def _estimate_gas(self, initializer: bytes, salt_nonce: int,
                      payment_token: str, payment_receiver: 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 initializer: Data initializer to send to GnosisSafe setup method
        :param salt_nonce: Nonce that will be used to generate the salt to calculate
        the address of the new proxy contract.
        :return: Total gas estimation
        """

        # Estimate the contract deployment. We cannot estimate the refunding, as the safe address has not any fund
        gas: int = self.proxy_factory_contract.functions.createProxyWithNonce(self.master_copy_address,
                                                                              initializer, salt_nonce).estimateGas()

        # It's not very relevant if is 1 or 9999
        payment: int = 1

        # 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.estimateGas({'to': payment_receiver, 'value': payment})
        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
            gas += 55000
            # try:
            #     gas += get_erc20_contract(self.w3,
            #                               payment_token).functions.transfer(payment_receiver,
            #                                                                 payment).estimateGas({'from':
            #                                                                                      payment_token})
            # except ValueError as exc:
            #     raise InvalidERC20Token from exc

        return gas
def _estimate_gas(self, initializer: bytes, salt_nonce: int,
                      payment_token: str, payment_receiver: 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 initializer: Data initializer to send to GnosisSafe setup method
        :param salt_nonce: Nonce that will be used to generate the salt to calculate
        the address of the new proxy contract.
        :return: Total gas estimation
        """

        # Estimate the contract deployment. We cannot estimate the refunding, as the safe address has not any fund
        gas: int = self.proxy_factory_contract.functions.createProxyWithNonce(self.master_copy_address,
                                                                              initializer, salt_nonce).estimateGas()

        # It's not very relevant if is 1 or 9999
        payment: int = 1

        # 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.estimateGas({'to': payment_receiver, 'value': payment})
        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
            gas += 55000
            # try:
            #     gas += get_erc20_contract(self.w3,
            #                               payment_token).functions.transfer(payment_receiver,
            #                                                                 payment).estimateGas({'from':
            #                                                                                      payment_token})
            # except ValueError as exc:
            #     raise InvalidERC20Token from exc

        return gas
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 initializer: Data initializer to send to GnosisSafe setup method
        :param salt_nonce: Nonce that will be used to generate the salt to calculate
        the address of the new proxy contract.
        :return: Total gas estimation