Example #1
0
    def handle(self, *args, **options):
        ethereum_client = EthereumClientProvider()
        app_name = apps.get_app_config('history').verbose_name
        network_name = ethereum_client.get_network().name.capitalize()
        startup_message = f'Starting {app_name} version {__version__} on {network_name}'
        self.stdout.write(self.style.SUCCESS(startup_message))

        if settings.SLACK_API_WEBHOOK:
            try:
                r = requests.post(settings.SLACK_API_WEBHOOK,
                                  json={'text': startup_message})
                if r.ok:
                    self.stdout.write(
                        self.style.SUCCESS(
                            f'Slack configured, "{startup_message}" sent'))
                else:
                    raise RequestException()
            except RequestException as e:
                self.stdout.write(
                    self.style.ERROR(
                        f'Cannot send slack notification to webhook '
                        f'({settings.SLACK_API_WEBHOOK}): "{e}"'))
        else:
            self.stdout.write(
                self.style.SUCCESS('Slack not configured, ignoring'))
    def handle(self, *args, **options):
        for task in self.tasks:
            _, created = task.create_task()
            if created:
                self.stdout.write(self.style.SUCCESS('Created Periodic Task %s' % task.name))
            else:
                self.stdout.write(self.style.SUCCESS('Task %s was already created' % task.name))

        self.stdout.write(self.style.SUCCESS('Setting up Safe Contract Addresses'))
        ethereum_client = EthereumClientProvider()
        ethereum_network = ethereum_client.get_network()
        self.stdout.write(self.style.SUCCESS('Network %s was identified' % ethereum_network))
        if ethereum_network == EthereumNetwork.MAINNET:
            self.stdout.write(self.style.SUCCESS('Setting up Mainnet addresses'))
            self.setup_mainnet()
        elif ethereum_network == EthereumNetwork.RINKEBY:
            self.stdout.write(self.style.SUCCESS('Setting up Rinkeby addresses'))
            self.setup_rinkeby()
        elif ethereum_network == EthereumNetwork.GOERLI:
            self.stdout.write(self.style.SUCCESS('Setting up Goerli addresses'))
            self.setup_goerli()
        elif ethereum_network == EthereumNetwork.KOVAN:
            self.stdout.write(self.style.SUCCESS('Setting up Kovan addresses'))
            self.setup_kovan()
        elif ethereum_network == EthereumNetwork.UNKNOWN:
            self.stdout.write(self.style.SUCCESS('Setting up RSK addresses'))
            self.setup_rsk()
        else:
            self.stdout.write(self.style.WARNING(f'Cannot detect a valid ethereum-network'))
Example #3
0
    def handle(self, *args, **options):
        for task in TASKS:
            _, created = task.create_task()
            if created:
                self.stdout.write(
                    self.style.SUCCESS('Created Periodic Task %s' % task.name))
            else:
                self.stdout.write(
                    self.style.SUCCESS('Task %s was already created' %
                                       task.name))

        self.stdout.write(
            self.style.SUCCESS('Setting up Safe Contract Addresses'))
        ethereum_client = EthereumClientProvider()
        ethereum_network = ethereum_client.get_network()
        if ethereum_network in MASTER_COPIES:
            self.stdout.write(
                self.style.SUCCESS(
                    f'Setting up {ethereum_network.name} safe addresses'))
            self._setup_safe_master_copies(MASTER_COPIES[ethereum_network])
        if ethereum_network in PROXY_FACTORIES:
            self.stdout.write(
                self.style.SUCCESS(
                    f'Setting up {ethereum_network.name} proxy factory addresses'
                ))
            self._setup_safe_proxy_factories(PROXY_FACTORIES[ethereum_network])

        if not (ethereum_network in MASTER_COPIES
                and ethereum_network in PROXY_FACTORIES):
            self.stdout.write(
                self.style.WARNING('Cannot detect a valid ethereum-network'))
def fix_uniswap_pool_tokens_task() -> Optional[int]:
    ethereum_client = EthereumClientProvider()
    ethereum_network = ethereum_client.get_network()
    if ethereum_network == EthereumNetwork.MAINNET:
        try:
            number = Token.objects.fix_uniswap_pool_tokens()
            if number:
                logger.info('%d uniswap pool token names were fixed', number)
            return number
        finally:
            close_gevent_db_connection()
Example #5
0
    def handle(self, *args, **options):
        for task in TASKS:
            _, created = task.create_task()
            if created:
                self.stdout.write(
                    self.style.SUCCESS('Created Periodic Task %s' % task.name))
            else:
                self.stdout.write(
                    self.style.SUCCESS('Task %s was already created' %
                                       task.name))

        self.stdout.write(
            self.style.SUCCESS('Setting up Safe Contract Addresses'))
        ethereum_client = EthereumClientProvider()
        network_name = ethereum_client.get_network().name.capitalize()

        self.stdout.write(
            self.style.SUCCESS('Ethereum Network detected is %s.' %
                               ethereum_client.get_network()))
        self.setup_my_network()
def fix_pool_tokens_task() -> Optional[int]:
    """
    Fix names for generic pool tokens, like Balancer or Uniswap
    :return: Number of pool token names updated
    """
    ethereum_client = EthereumClientProvider()
    ethereum_network = ethereum_client.get_network()
    if ethereum_network == EthereumNetwork.MAINNET:
        try:
            number = Token.pool_tokens.fix_all_pool_tokens()
            if number:
                logger.info('%d pool token names were fixed', number)
            return number
        finally:
            close_gevent_db_connection()
Example #7
0
def index_contracts_metadata_task(addresses: Sequence[str]):
    ethereum_client = EthereumClientProvider()
    ethereum_network = ethereum_client.get_network()
    try:
        for address in addresses:
            try:
                with transaction.atomic():
                    if contract := Contract.objects.create_from_address(
                            address, network_id=ethereum_network.value):
                        logger.info(
                            'Indexed contract with address=%s name=%s abi-present=%s',
                            address, contract.name,
                            bool(contract.contract_abi.abi))
                    else:
                        Contract.objects.create(address=address)
            except IntegrityError:
                logger.warning('Contract with address=%s was already created',
                               address)
Example #8
0
    def handle(self, *args, **options):
        self.stdout.write(self.style.SUCCESS("Removing old tasks"))
        PeriodicTask.objects.filter(
            task__startswith="safe_transaction_service"
        ).delete()
        self.stdout.write(self.style.SUCCESS("Old tasks were removed"))

        for task in TASKS:
            _, created = task.create_task()
            if created:
                self.stdout.write(
                    self.style.SUCCESS("Created Periodic Task %s" % task.name)
                )
            else:
                self.stdout.write(
                    self.style.SUCCESS("Task %s was already created" % task.name)
                )

        self.stdout.write(self.style.SUCCESS("Setting up Safe Contract Addresses"))
        ethereum_client = EthereumClientProvider()
        ethereum_network = ethereum_client.get_network()
        if ethereum_network in MASTER_COPIES:
            self.stdout.write(
                self.style.SUCCESS(f"Setting up {ethereum_network.name} safe addresses")
            )
            self._setup_safe_master_copies(MASTER_COPIES[ethereum_network])
        if ethereum_network in PROXY_FACTORIES:
            self.stdout.write(
                self.style.SUCCESS(
                    f"Setting up {ethereum_network.name} proxy factory addresses"
                )
            )
            self._setup_safe_proxy_factories(PROXY_FACTORIES[ethereum_network])

        if not (
            ethereum_network in MASTER_COPIES and ethereum_network in PROXY_FACTORIES
        ):
            self.stdout.write(
                self.style.WARNING("Cannot detect a valid ethereum-network")
            )
    def handle(self, *args, **options):
        every_contract = options['all']
        scraper = options['scraper']
        if scraper:
            etherscan_client = EtherscanClient()

        ethereum_client = EthereumClientProvider()
        network = ethereum_client.get_network()

        contract_queryset = Contract.objects.all()
        if not every_contract:
            contract_queryset = contract_queryset.filter(contract_abi=None)

        for contract in contract_queryset:
            if not scraper:
                if contract.sync_abi_from_api(network=network):
                    self.stdout.write(
                        self.style.SUCCESS(
                            f'Synced contract {contract.address} - {contract.name}'
                        ))
            else:
                try:
                    contract_info = etherscan_client.get_contract_info(
                        contract.address)
                    if contract_info:
                        contract_abi, _ = ContractAbi.objects.update_or_create(
                            abi=contract_info.abi,
                            defaults={'description': contract_info.name})
                        contract, _ = Contract.objects.update_or_create(
                            address=contract_info.abi,
                            defaults={
                                'name': contract_info.name,
                                'abi': contract_abi
                            })
                        self.stdout.write(
                            self.style.SUCCESS(
                                f'Synced contract {contract.address} - {contract.name}'
                            ))
                except EtherscanClientException:
                    time.sleep(5)