def test_get_dtfactory_address(config): addresses = util.get_contracts_addresses(config.address_file, "ganache") assert addresses assert isinstance(addresses, dict) assert "DTFactory" in addresses address = get_dtfactory_address(config.address_file, "ganache") assert address[:2] == "0x", "It is not a token address." assert address == addresses["DTFactory"]
def _get_all_liquidity_records(self, action, web3, pool_address, block_number=None, to_block=None, token_address=None, raw_result=True): action_to_fn = { 'join': 'get_join_logs', 'exit': 'get_exit_logs', 'swap': 'get_swap_logs' } current_block = to_block if to_block is not None else web3.eth.blockNumber pool = BPool(pool_address) dt_address = token_address or self.get_token_address( pool_address, pool) factory = DTFactory(get_dtfactory_address()) if block_number is None: block_number = factory.get_token_registered_event( 0, current_block, token_address=dt_address).blockNumber logs = getattr(pool, action_to_fn[action])(web3, block_number, current_block) if raw_result: return logs _all = [] for l in logs: if action == 'join': record = (l.args.caller, l.args.tokenIn, l.args.tokenAmountIn, 0, 0, l.blockNumber, l.transactionHash, 'join') elif action == 'exit': record = (l.args.caller, l.args.tokenOut, l.args.tokenAmountOut, 0, 0, l.blockNumber, l.transactionHash, 'exit') else: assert action == 'swap', f'Unknown pool action {action}' record = (l.args.caller, l.args.tokenIn, l.args.tokenAmountIn, l.args.tokenOut, l.args.tokenAmountOut, l.blockNumber, l.transactionHash, 'swap') _all.append(record) return _all
def search_exchange_by_data_token(self, data_token: str) -> List[AttributeDict]: dtfactory_address = get_dtfactory_address(self._config.address_file, web3=self._web3) dtfactory = DTFactory(self._web3, dtfactory_address) token_registered_log = dtfactory.get_token_registered_event( 0, self._web3.eth.block_number, data_token) assert (token_registered_log ), f"No token with '{data_token}' address was created before." from_block = token_registered_log.blockNumber fre = self._exchange_contract() filter_args = {"dataToken": data_token} logs = fre.get_event_logs( event_name="ExchangeCreated", from_block=from_block, to_block=self._web3.eth.block_number, filters=filter_args, ) return logs
def _get_all_liquidity_records( self, action, web3, pool_address, block_number=None, to_block=None, token_address=None, raw_result=True, ): action_to_fn = { "join": "get_join_logs", "exit": "get_exit_logs", "swap": "get_swap_logs", } current_block = to_block if to_block is not None else web3.eth.blockNumber pool = BPool(pool_address) dt_address = token_address or self.get_token_address( pool_address, pool) factory = DTFactory(get_dtfactory_address()) if block_number is None: block_number = factory.get_token_registered_event( 0, current_block, token_address=dt_address).blockNumber logs = getattr(pool, action_to_fn[action])(web3, block_number, current_block) if raw_result: return logs _all = [] for lg in logs: if action == "join": record = ( lg.args.caller, lg.args.tokenIn, lg.args.tokenAmountIn, 0, 0, lg.blockNumber, lg.transactionHash, "join", ) elif action == "exit": record = ( lg.args.caller, lg.args.tokenOut, lg.args.tokenAmountOut, 0, 0, lg.blockNumber, lg.transactionHash, "exit", ) else: assert action == "swap", f"Unknown pool action {action}" record = ( lg.args.caller, lg.args.tokenIn, lg.args.tokenAmountIn, lg.args.tokenOut, lg.args.tokenAmountOut, lg.blockNumber, lg.transactionHash, "swap", ) _all.append(record) return _all
def __init__( self, config: Union[Dict, Config], data_provider: Optional[Type] = None ) -> None: """Initialize Ocean class. Usage: Make a new Ocean instance `ocean = Ocean({...})` This class provides the main top-level functions in ocean protocol: 1. Publish assets metadata and associated services - Each asset is assigned a unique DID and a DID Document (DDO) - The DDO contains the asset's services including the metadata - The DID is registered on-chain with a URL of the metadata store to retrieve the DDO from `asset = ocean.assets.create(metadata, publisher_wallet)` 2. Discover/Search assets via the current configured metadata store (Aquarius) - Usage: `assets_list = ocean.assets.search('search text')` An instance of Ocean is parameterized by a `Config` instance. :param config: `Config` instance :param data_provider: `DataServiceProvider` instance """ if isinstance(config, dict): # fallback to metadataStoreUri cache_key = ( "metadataCacheUri" if ("metadataCacheUri" in config) else "metadataStoreUri" ) metadata_cache_uri = config.get( cache_key, config.get("metadata_cache_uri", "http://localhost:5000") ) config_dict = { "eth-network": {"network": config.get("network", "")}, "resources": { "metadata_cache_uri": metadata_cache_uri, "provider.url": config.get("providerUri", "http://localhost:8030"), }, } config = Config(options_dict=config_dict) self.config = config self.web3 = get_web3(self.config.network_url) if not data_provider: data_provider = DataServiceProvider network = get_network_name(web3=self.web3) addresses = get_contracts_addresses(self.config.address_file, network) self.assets = OceanAssets( self.config, self.web3, data_provider, addresses.get(MetadataContract.CONTRACT_NAME), ) self.compute = OceanCompute(self.config, data_provider) ocean_address = get_ocean_token_address(self.config.address_file, network) self.pool = OceanPool( self.web3, ocean_address, get_bfactory_address(self.config.address_file, network), get_dtfactory_address(self.config.address_file, network), ) self.exchange = OceanExchange( self.web3, ocean_address, FixedRateExchange.configured_address(network, self.config.address_file), self.config, ) logger.debug("Ocean instance initialized: ")