def get_udc_and_corresponding_token_from_dependencies( chain_id: ChainID, proxy_manager: ProxyManager, development_environment: ContractDevEnvironment, udc_address: ChecksumAddress = None, ) -> Tuple[UserDeposit, CustomToken]: """Return contract proxies for the UserDepositContract and associated token. This will return a proxy to the `UserDeposit` contract as determined by the **local** Raiden depedency. """ if udc_address is None: contracts = get_contracts_deployment_info( chain_id, version=RAIDEN_CONTRACT_VERSION, development_environment=development_environment, ) msg = (f"invalid chain_id, {chain_id} is not available " f"for version {RAIDEN_CONTRACT_VERSION}") assert contracts, msg udc_address = contracts["contracts"][CONTRACT_USER_DEPOSIT]["address"] userdeposit_proxy = proxy_manager.user_deposit( UserDepositAddress(to_canonical_address(udc_address)), "latest") token_address = userdeposit_proxy.token_address("latest") user_token_proxy = proxy_manager.custom_token(token_address, "latest") return userdeposit_proxy, user_token_proxy
def setup_token_contract_for_token_network( self, proxy_manager: ProxyManager) -> CustomToken: """Ensure there is a deployed token contract and return a `CustomToken` proxy to it. This token will be used for the scenario's token network. This will either: - Use the token from the address provided in the scenario configuration. - Use a previously deployed token, with the details loaded from the disk. - Deploy a new token if neither of the above options is used. """ token_definition = self.definition.token reuse_token_from_file = token_definition.can_reuse_token if token_definition.address: token_address = to_canonical_address(token_definition.address) elif reuse_token_from_file: token_details = load_token_configuration_from_file( token_definition.token_file) token_address = to_canonical_address(token_details["address"]) else: contract_data = proxy_manager.contract_manager.get_contract( CONTRACT_CUSTOM_TOKEN) contract, receipt = self.client.deploy_single_contract( contract_name=CONTRACT_CUSTOM_TOKEN, contract=contract_data, constructor_parameters=( ORCHESTRATION_MAXIMUM_BALANCE, token_definition.decimals, token_definition.name, token_definition.symbol, ), ) token_address = to_canonical_address(contract.address) if token_definition.should_reuse_token: details = TokenDetails({ "name": token_definition.name, "address": to_checksum_address(token_address), "block": receipt["blockNumber"], }) save_token_configuration_to_file(token_definition.token_file, details) return proxy_manager.custom_token(TokenAddress(token_address), "latest")