Example #1
0
    def _initialize_udc(
        self, gas_limit: int, node_count: int
    ) -> Tuple[Set[TransactionHash], Optional[ContractProxy], bool]:
        our_address = to_checksum_address(self.client.address)
        udc_settings = self.yaml.settings.services.udc
        udc_enabled = udc_settings.enable

        ud_token_tx = set()

        if not udc_enabled:
            return ud_token_tx, None, False

        udc_ctr, ud_token_ctr = get_udc_and_token(self)

        ud_token_address = to_checksum_address(ud_token_ctr.contract_address)
        udc_address = to_checksum_address(udc_ctr.contract_address)

        log.info("UDC enabled", contract_address=udc_address, token_address=ud_token_address)

        self.udc = UserDepositContract(self, udc_ctr, ud_token_ctr)

        should_deposit_ud_token = udc_enabled and udc_settings.token["deposit"]
        allowance_tx = self.udc.update_allowance()
        if allowance_tx:
            ud_token_tx.add(allowance_tx)
        if should_deposit_ud_token:

            tx = self.udc.mint(our_address)
            if tx:
                ud_token_tx.add(tx)

        return ud_token_tx, udc_ctr, should_deposit_ud_token
Example #2
0
    def _initialize_udc(
        self,
        gas_limit: int,
        node_count: int,
    ) -> Tuple[Set[TransactionHash], Optional[ContractProxy], bool]:
        our_address = to_checksum_address(self.client.address)
        udc_settings = self.scenario.services.get('udc', {})
        udc_enabled = udc_settings.get('enable')

        ud_token_tx = set()

        if not udc_enabled:
            return ud_token_tx, None, False

        udc_ctr, ud_token_ctr = get_udc_and_token(self)

        ud_token_address = to_checksum_address(ud_token_ctr.contract_address)
        udc_address = to_checksum_address(udc_ctr.contract_address)

        log.info(
            'UDC enabled',
            contract_address=udc_address,
            token_address=ud_token_address,
        )

        should_deposit_ud_token = (udc_enabled and udc_settings.get(
            'token', {}).get('deposit', False))
        if should_deposit_ud_token:
            tx = mint_token_if_balance_low(
                token_contract=ud_token_ctr,
                target_address=our_address,
                min_balance=DEFAULT_TOKEN_BALANCE_FUND * node_count,
                fund_amount=DEFAULT_TOKEN_BALANCE_FUND * 10 * node_count,
                gas_limit=gas_limit,
                mint_msg="Minting UD tokens",
                no_action_msg="UD token balance sufficient",
            )
            if tx:
                ud_token_tx.add(tx)

            udt_allowance = (ud_token_ctr.contract.functions.allowance(
                our_address, udc_address).call())
            if udt_allowance < DEFAULT_TOKEN_BALANCE_FUND * node_count:
                allow_amount = (DEFAULT_TOKEN_BALANCE_FUND * 10 *
                                node_count) - udt_allowance
                log.debug('Updating UD token allowance',
                          allowance=allow_amount)
                ud_token_tx.add(
                    ud_token_ctr.transact('approve', gas_limit, udc_address,
                                          allow_amount), )
            else:
                log.debug('UD token allowance sufficient',
                          allowance=udt_allowance)
        return ud_token_tx, udc_ctr, should_deposit_ud_token