diff --git a/.gitbook/assets/big-money.gif b/.gitbook/assets/big-money.gif new file mode 100644 index 00000000..9276d391 Binary files /dev/null and b/.gitbook/assets/big-money.gif differ diff --git a/SUMMARY.md b/SUMMARY.md index 5f3d1641..dfc896ef 100644 --- a/SUMMARY.md +++ b/SUMMARY.md @@ -97,9 +97,8 @@ * [Compute Endpoints](developers/provider/compute-endpoints.md) * [Authentication Endpoints](developers/provider/authentication-endpoints.md) * [📊 Data Science](data-science/README.md) - * [The Data Value Creation Loop](data-science/the-data-value-creation-loop.md) - * [Examples of useful data](data-science/data-engineers.md) - * [Examples of useful models](data-science/data-scientists.md) + * [Data Value Creation Loop](data-science/the-data-value-creation-loop.md) + * [What data is valuable?](data-science/data-engineers.md) * [Benefits of Ocean for Data Science](data-science/benefits-of-ocean-for-data-science.md) * [🔨 Infrastructure](infrastructure/README.md) * [Setup a Server](infrastructure/setup-server.md) diff --git a/data-science/data-engineers.md b/data-science/data-engineers.md index a9f33c15..801bfc63 100644 --- a/data-science/data-engineers.md +++ b/data-science/data-engineers.md @@ -1,11 +1,29 @@ -# Examples of useful data +--- +description: How to research where supply meets demand... 💰🧑‍🏫 +--- -Here's the game: Go get useful data and publish it on Ocean. Curating useful datasets is the critical early step in the data value creation loop. The first ones to publish useful datasets will be well-positioned to have others build on their work and kickstart additional data value creation. Those that start this process can kickstart value creation by working with Ocean Protocol to [sponsor a data challenge](data-challenges/hosting-a-data-challenge.md). +# What data is valuable? + +
+ +### Simple Truths + +A lot of people miss the mark on tokenizing data that actually _sells_. If your goal is to make money, then you have to research target audiences, who's currently buying data, and \*correctly price\* your data to meet that demand. + +To figure out which market segments are paying for data, then it may help you to **go to the Ocean Market and sort by Sales.** + +But even then, it's not enough to just publish useful data on Ocean. **You need to market your data** **assets** to close sales. + +Have you tried all these things and are still having trouble making money? Never fear! You can enter one of our [data challenges](https://oceanprotocol.com/challenges) to make sweet OCEAN rewards and build your data science skills. + +But what if you're a well-heeled company looking to create dApps or source data predictions? You can kickstart the value creation loop by working with Ocean Protocol to [sponsor a data challenge](data-challenges/hosting-a-data-challenge.md). + +### Brainstorming Useful Data to Upload Below is a short list of potential areas to curate useful data. * **Government Open Data:** Governments serve as a rich and reliable source of data. However, this data often lacks proper documentation or poses challenges for data scientists to work with effectively. Establishing robust Extract, Transform, Load (ETL) pipelines enhance accessibility to government open data. This way, others can tap into this wealth of information without unnecessary hurdles. For example, in one of our [data challenges](https://desights.ai/shared/challenge/8) we leveraged public real estate data from Dubai to build use cases for understanding and predicting valuations and rents. Local, state, and federal governments around the world provide access to valuable data. Build pipelines to make consuming that data easier and help others build useful products to help your local community. -* **Public APIs:** A wide range of freely available public APIs covers various data verticals. Leveraging these APIs, data engineers can construct pipelines that enable efficient access and utilization of the data. [This ](https://github.com/public-apis/public-apis)is a public repository of public APIs for a wide range of topics, from weather to gaming to finance. +* **Public APIs:** A wide range of freely available public APIs covers various data verticals. Leveraging these APIs, data engineers can construct pipelines that enable efficient access and utilization of the data. [This ](https://github.com/public-apis/public-apis)is a repository of public APIs for a wide range of topics, from weather to gaming to finance. * **On-Chain Data:** Blockchain data presents a unique opportunity for data engineers to curate high-quality data. There is consistent demand for well-curated decentralized finance (DeFi) data and an emerging need for curated data in other domains, such as decentralized social data. Build datasets for a range of use cases such as trading to customer analytics * **Datasets for training foundation models:** Build pipelines for training foundation models. Conduct web scraping and aggregate existing commercially licensed datasets * **Datasets for fine-tuning foundation models:** Curate high-quality labeled datasets to fine-tune foundation models. label the outputs of models or create diff --git a/data-science/data-scientists.md b/data-science/data-scientists.md deleted file mode 100644 index c75e135d..00000000 --- a/data-science/data-scientists.md +++ /dev/null @@ -1,21 +0,0 @@ -# Examples of useful models - -Data scientists armed with access to high-quality datasets are now primed to build useful models for a variety of use cases. Model building is often the most enjoyable part of the - - - -* **Government Open Data** - * Real Estate Valuation Model: Use real estate data to build a machine learning model that predicts property valuations. This can be useful for both buyers and sellers to understand market trends. - * Traffic Management System: Utilize transportation data to develop an AI-based traffic management system that predicts traffic congestion and suggests optimal routes. - * Disease Prediction and Outbreak Management: Leverage healthcare data to build a machine learning model for disease prediction and management of potential outbreaks. -* **Public APIs** - * Weather Forecast Model: Using weather APIs, build a machine learning model to accurately predict weather conditions. This can be beneficial for farmers, event organizers, and other stakeholders. - * Stock Market Trend Analysis: Leverage financial APIs to create a predictive model for stock market trends, providing insights for investors. -* **On-Chain Data** - * Web3 Customer Cohort Analysis: Build a model to analyze the user activity of DeFi protocols to understand their major customer cohorts and their various key metrics like retention rate and customer lifetime value. Sell the model as a B2B product for protocols to improve their business or as premium research for traders - * DeFi Credit Scoring System: Build a decentralized finance credit scoring system using DeFi data, allowing for more accurate risk assessment in lending and unlocking under collateralized lending in DeFi. - * Social Data Analysis: Using decentralized social data, create a model that analyses trends, sentiments, and behaviors in decentralized social platforms. -* **Fine-Tuned Foundation Models** - * Personalized Recommendation System: Fine-tune an existing foundation model with labeled datasets to create a recommendation system that can be personalized based on individual user preferences. - * Medical Diagnosis Assistance: Train a model with labeled medical images to assist in diagnosing a wide range of diseases. - * Customized Chatbot: Fine-tune a conversational AI model with labeled conversational data to create a chatbot customized to specific industries or companies. diff --git a/developers/ocean.py/datatoken-interface-tech-details.md b/developers/ocean.py/datatoken-interface-tech-details.md index ae6e82f5..b01719a6 100644 --- a/developers/ocean.py/datatoken-interface-tech-details.md +++ b/developers/ocean.py/datatoken-interface-tech-details.md @@ -82,3 +82,505 @@ Return value is a hex string which denotes the transaction hash of dispenser dep +### Dispense Datatokens + +* **dispense**(`self`, `amount: Union[int, str]`, `tx_dict: dict`) + +This function is used to retrieve funds or datatokens for an user who wants to start an order. + +It is implemented in DatatokenBase, so it can be called within Datatoken class. + +**Parameters** + +* `amount` - amount of datatokens to be dispensed in wei (int or string format) +* `tx_dict` - is the configuration `dictionary` for that specific transaction. Usually for `development` we include just the `from` wallet, but for remote networks, you can provide gas fees, required confirmations for that block etc. For more info, check [Brownie docs](https://eth-brownie.readthedocs.io/en/stable/). + +**Returns** + +`str` + +Return value is a hex string which denotes the transaction hash of dispensed datatokens, like a proof. + +**Defined in** + +[models/datatoken.py](https://github.com/oceanprotocol/ocean.py/blob/4aa12afd8a933d64bc2ed68d1e5359d0b9ae62f9/ocean\_lib/models/datatoken.py#LL379C5-L400C18) + +
+ +Source code + +```python + @enforce_types + def dispense(self, amount: Union[int, str], tx_dict: dict): + """ + Dispense free tokens via the dispenser faucet. + + :param: amount - number of tokens to dispense, in wei + :tx_dict: e.g. {"from": alice_wallet} + :return: tx + """ + # args for contract tx + datatoken_addr = self.address + from_addr = ( + tx_dict["from"].address + if hasattr(tx_dict["from"], "address") + else tx_dict["from"] + ) + + # do contract tx + tx = self._ocean_dispenser().dispense( + datatoken_addr, amount, from_addr, tx_dict + ) + return tx +``` + +
+ +### Dispense Datatokens & Order + +* **dispense\_and\_order**(`self`, `consumer: str`, `service_index: int`, `provider_fees: dict`, `transaction_parameters: dict`, `consume_market_fees=None`) -> `str` + +This function is used to retrieve funds or datatokens for an user who wants to start an order. + +It is implemented in `Datatoken2`, so it can be called within `Datatoken2` class (using the enterprise template). + +**Parameters** + +* `consumer` - address of the consumer wallet that needs funding +* `service_index` - service index as int for identifying the service that you want to further call [`start_order`](https://github.com/oceanprotocol/ocean.py/blob/4aa12afd8a933d64bc2ed68d1e5359d0b9ae62f9/ocean\_lib/models/datatoken.py#LL169C5-L197C10). +* `transaction_parameters` - is the configuration `dictionary` for that specific transaction. Usually for `development` we include just the `from` wallet, but for remote networks, you can provide gas fees, required confirmations for that block etc. For more info, check [Brownie docs](https://eth-brownie.readthedocs.io/en/stable/). +* `consume_market_fees` - [`TokenInfo` ](https://github.com/oceanprotocol/ocean.py/blob/4aa12afd8a933d64bc2ed68d1e5359d0b9ae62f9/ocean\_lib/models/datatoken.py#L31)object which contains the consume market fee amount, address & token address. If it is not explicitly specified, by default it has an empty `TokenInfo` object. + +**Returns** + +`str` + +Return value is a hex string which denotes the transaction hash of dispensed datatokens, like a proof of starting order. + +**Defined in** + +[models/datatoken.py](https://github.com/oceanprotocol/ocean.py/blob/4aa12afd8a933d64bc2ed68d1e5359d0b9ae62f9/ocean\_lib/models/datatoken.py#LL439C5-L483C1) + +
+ +Source code + +{% code overflow="wrap" %} +```python +def dispense_and_order( + self, + consumer: str, + service_index: int, + provider_fees: dict, + transaction_parameters: dict, + consume_market_fees=None, + ) -> str: + if not consume_market_fees: + consume_market_fees = TokenFeeInfo() + + buyer_addr = ( + transaction_parameters["from"].address + if hasattr(transaction_parameters["from"], "address") + else transaction_parameters["from"] + ) + + bal = from_wei(self.balanceOf(buyer_addr)) + if bal < 1.0: + dispenser_addr = get_address_of_type(self.config_dict, "Dispenser") + from ocean_lib.models.dispenser import Dispenser # isort: skip + + dispenser = Dispenser(self.config_dict, dispenser_addr) + + # catch key failure modes + st = dispenser.status(self.address) + active, allowedSwapper = st[0], st[6] + if not active: + raise ValueError("No active dispenser for datatoken") + if allowedSwapper not in [ZERO_ADDRESS, buyer_addr]: + raise ValueError(f"Not allowed. allowedSwapper={allowedSwapper}") + + # Try to dispense. If other issues, they'll pop out + dispenser.dispense( + self.address, "1 ether", buyer_addr, transaction_parameters + ) + + return self.start_order( + consumer=ContractBase.to_checksum_address(consumer), + service_index=service_index, + provider_fees=provider_fees, + consume_market_fees=consume_market_fees, + transaction_parameters=transaction_parameters, + ) +``` +{% endcode %} + +
+ +### Dispenser Status + +* **dispenser\_status**(`self`) -> `DispenserStatus` + +**Returns** + +`DispenserStatus` + +Returns a `DispenserStatus` object returned from `Dispenser.sol::status(dt_addr)` which is composed of: + +* bool active +* address owner +* bool isMinter +* uint256 maxTokens +* uint256 maxBalance +* uint256 balance +* address allowedSwapper + +These are Solidity return values & types, but `uint256` means int in Python and `address` is a `string` instance. + +For tips & tricks, check [this section](https://github.com/oceanprotocol/ocean.py/blob/4aa12afd8a933d64bc2ed68d1e5359d0b9ae62f9/READMEs/main-flow.md#faucet-tips--tricks) from the [README](https://github.com/oceanprotocol/ocean.py/blob/4aa12afd8a933d64bc2ed68d1e5359d0b9ae62f9/READMEs/main-flow.md). + +It is implemented in `DatatokenBase`, inherited by `Datatoken2`, so it can be called within both instances. + +**Defined in** + +[models/datatoken.py](https://github.com/oceanprotocol/ocean.py/blob/4aa12afd8a933d64bc2ed68d1e5359d0b9ae62f9/ocean\_lib/models/datatoken.py#LL402C1-L409C43) + +
+ +Source code + +```python +@enforce_types + def dispenser_status(self): + """:return: DispenserStatus object""" + # import here to avoid circular import + from ocean_lib.models.dispenser import DispenserStatus + + status_tup = self._ocean_dispenser().status(self.address) + return DispenserStatus(status_tup) +``` + +
+ +### Create Fixed Rate Exchange + +* **create\_exchange**(`self`, `rate: Union[int, str]`, `base_token_addr: str`, `tx_dict: dict`, `owner_addr: Optional[str] = None`, `publish_market_fee_collector: Optional[str] = None, publish_market_fee: Union[int, str] = 0`, `with_mint: bool = False`, `allowed_swapper: str = ZERO_ADDRESS`, `full_info: bool = False`) -> `Union[OneExchange, tuple]` + +It is implemented in `DatatokenBase`, inherited by `Datatoken2`, so it can be called within both instances. + +For this datatoken, create a single fixed-rate exchange (`OneExchange`). + +This wraps the smart contract method `Datatoken.createFixedRate()` with a simpler interface. + +**Parameters** + +* `rate` - how many base tokens does 1 datatoken cost? In wei or string +* `base_token_addr` - e.g. OCEAN address +* `tx_dict` - is the configuration `dictionary` for that specific transaction. Usually for `development` we include just the `from` wallet, but for remote networks, you can provide gas fees, required confirmations for that block etc. For more info, check [Brownie docs](https://eth-brownie.readthedocs.io/en/stable/). + +**Optional parameters** + +* `owner_addr` - owner of the datatoken +* `publish_market_fee_collector` - fee going to publish market address +* `publish_market_fee` - in wei or string, e.g. `int(1e15)` or `"0.001 ether"` +* `with_mint` - should the exchange mint datatokens as needed (`True`), or do they need to be supplied/allowed by participants like base token (`False`)? +* `allowed_swapper` - if `ZERO_ADDRESS`, anyone can swap +* `full_info` - return just `OneExchange`, or `(OneExchange, )` + +**Returns** + +* `exchange` - OneExchange +* (maybe) `tx_receipt` + +**Defined in** + +[models/datatoken.py](https://github.com/oceanprotocol/ocean.py/blob/4aa12afd8a933d64bc2ed68d1e5359d0b9ae62f9/ocean\_lib/models/datatoken.py#LL236C4-L310C1) + +
+ +Source code + +{% code overflow="wrap" %} +```python +@enforce_types + def create_exchange( + self, + rate: Union[int, str], + base_token_addr: str, + tx_dict: dict, + owner_addr: Optional[str] = None, + publish_market_fee_collector: Optional[str] = None, + publish_market_fee: Union[int, str] = 0, + with_mint: bool = False, + allowed_swapper: str = ZERO_ADDRESS, + full_info: bool = False, + ) -> Union[OneExchange, tuple]: + + # import now, to avoid circular import + from ocean_lib.models.fixed_rate_exchange import OneExchange + + FRE_addr = get_address_of_type(self.config_dict, "FixedPrice") + from_addr = ( + tx_dict["from"].address + if hasattr(tx_dict["from"], "address") + else tx_dict["from"] + ) + BT = Datatoken(self.config_dict, base_token_addr) + owner_addr = owner_addr or from_addr + publish_market_fee_collector = publish_market_fee_collector or from_addr + + tx = self.contract.createFixedRate( + checksum_addr(FRE_addr), + [ + checksum_addr(BT.address), + checksum_addr(owner_addr), + checksum_addr(publish_market_fee_collector), + checksum_addr(allowed_swapper), + ], + [ + BT.decimals(), + self.decimals(), + rate, + publish_market_fee, + with_mint, + ], + tx_dict, + ) + + exchange_id = tx.events["NewFixedRate"]["exchangeId"] + FRE = self._FRE() + exchange = OneExchange(FRE, exchange_id) + if full_info: + return (exchange, tx) + return exchange +``` +{% endcode %} + +
+ +### Buy Datatokens & Order + +* **buy\_DT\_and\_order**(`self`, `consumer: str`, `service_index: int`, `provider_fees: dict`, `exchange: Any`, `transaction_parameters: dict`, `consume_market_fees=None`) -> `str` + +This function is used to retrieve funds or datatokens for an user who wants to start an order. + +It is implemented in `Datatoken` class and it is also inherited in `Datatoken2` class. + +**Parameters** + +* `consumer` - address of the consumer wallet that needs funding +* `service_index` - service index as int for identifying the service that you want to further call [`start_order`](https://github.com/oceanprotocol/ocean.py/blob/4aa12afd8a933d64bc2ed68d1e5359d0b9ae62f9/ocean\_lib/models/datatoken.py#LL169C5-L197C10). +* `transaction_parameters` - is the configuration `dictionary` for that specific transaction. Usually for `development` we include just the `from` wallet, but for remote networks, you can provide gas fees, required confirmations for that block etc. For more info, check [Brownie docs](https://eth-brownie.readthedocs.io/en/stable/). +* `consume_market_fees` - [`TokenInfo` ](https://github.com/oceanprotocol/ocean.py/blob/4aa12afd8a933d64bc2ed68d1e5359d0b9ae62f9/ocean\_lib/models/datatoken.py#L31)object which contains the consume market fee amount, address & token address. If it is not explicitly specified, by default it has an empty `TokenInfo` object. + +**Returns** + +`str` + +Return value is a hex string for transaction hash which denotes the proof of starting order. + +**Defined in** + +[models/datatoken.py](https://github.com/oceanprotocol/ocean.py/blob/4aa12afd8a933d64bc2ed68d1e5359d0b9ae62f9/ocean\_lib/models/datatoken.py#LL484C4-L518C10) + +
+ +Source code + +```python + @enforce_types + def buy_DT_and_order( + self, + consumer: str, + service_index: int, + provider_fees: dict, + exchange: Any, + transaction_parameters: dict, + consume_market_fees=None, + ) -> str: + fre_address = get_address_of_type(self.config_dict, "FixedPrice") + + # import now, to avoid circular import + from ocean_lib.models.fixed_rate_exchange import OneExchange + + if not consume_market_fees: + consume_market_fees = TokenFeeInfo() + + if not isinstance(exchange, OneExchange): + exchange = OneExchange(fre_address, exchange) + + exchange.buy_DT( + datatoken_amt=to_wei(1), + consume_market_fee_addr=consume_market_fees.address, + consume_market_fee=consume_market_fees.amount, + tx_dict=transaction_parameters, + ) + + return self.start_order( + consumer=ContractBase.to_checksum_address(consumer), + service_index=service_index, + provider_fees=provider_fees, + consume_market_fees=consume_market_fees, + transaction_parameters=transaction_parameters, + ) + + +``` + +
+ +### Get Exchanges + +* **get\_exchanges**(`self`) -> `list` + +**Returns** + +`list` + +Returns `List[OneExchange]` - all the exchanges for this datatoken. + +It is implemented in `DatatokenBase`, inherited by `Datatoken2`, so it can be called within both instances. + +**Defined in** + +[models/datatoken.py](https://github.com/oceanprotocol/ocean.py/blob/4aa12afd8a933d64bc2ed68d1e5359d0b9ae62f9/ocean\_lib/models/datatoken.py#LL311C4-L322C25) + +
+ +Source code + +{% code overflow="wrap" %} +```python +@enforce_types + def get_exchanges(self) -> list: + """return List[OneExchange] - all the exchanges for this datatoken""" + # import now, to avoid circular import + from ocean_lib.models.fixed_rate_exchange import OneExchange + + FRE = self._FRE() + addrs_and_exchange_ids = self.getFixedRates() + exchanges = [ + OneExchange(FRE, exchange_id) for _, exchange_id in addrs_and_exchange_ids + ] + return exchanges +``` +{% endcode %} + +
+ +### Start Order + +* **start\_order**(`self`, `consumer: str`, `service_index: int`, `provider_fees: dict`, `transaction_parameters: dict`, `consume_market_fees=None`) -> `str` + +Starting order of a certain datatoken. + +It is implemented in Datatoken class and it is also inherited in Datatoken2 class. + +**Parameters** + +* `consumer` - address of the consumer wallet that needs funding +* `service_index` - service index as int for identifying the service that you want to apply `start_order`. +* `provider_fees` - dictionary which includes provider fees generated when `initialize` endpoint from `Provider` was called. +* `transaction_parameters` - is the configuration `dictionary` for that specific transaction. Usually for `development` we include just the `from` wallet, but for remote networks, you can provide gas fees, required confirmations for that block etc. For more info, check [Brownie docs](https://eth-brownie.readthedocs.io/en/stable/). +* `consume_market_fees` - [`TokenInfo` ](https://github.com/oceanprotocol/ocean.py/blob/4aa12afd8a933d64bc2ed68d1e5359d0b9ae62f9/ocean\_lib/models/datatoken.py#L31)object which contains the consume market fee amount, address & token address. If it is not explicitly specified, by default it has an empty `TokenInfo` object. + +**Returns** + +`str` + +Return value is a hex string for transaction hash which denotes the proof of starting order. + +**Defined in** + +[models/datatoken.py](https://github.com/oceanprotocol/ocean.py/blob/4aa12afd8a933d64bc2ed68d1e5359d0b9ae62f9/ocean\_lib/models/datatoken.py#LL169C5-L197C10) + +
+ +Source code + +```python +@enforce_types + def start_order( + self, + consumer: str, + service_index: int, + provider_fees: dict, + transaction_parameters: dict, + consume_market_fees=None, + ) -> str: + + if not consume_market_fees: + consume_market_fees = TokenFeeInfo() + + return self.contract.startOrder( + checksum_addr(consumer), + service_index, + ( + checksum_addr(provider_fees["providerFeeAddress"]), + checksum_addr(provider_fees["providerFeeToken"]), + int(provider_fees["providerFeeAmount"]), + provider_fees["v"], + provider_fees["r"], + provider_fees["s"], + provider_fees["validUntil"], + provider_fees["providerData"], + ), + consume_market_fees.to_tuple(), + transaction_parameters, + ) +``` + +
+ +### Reuse Order + +* **reuse\_order**(`self`, `order_tx_id: Union[str, bytes]`, `provider_fees: dict`, `transaction_parameters: dict` ) -> `str` + +Reusing an order from a certain datatoken. + +It is implemented in Datatoken class and it is also inherited in Datatoken2 class. + +**Parameters** + +* `order_tx_id` - transaction hash of a previous order, string or bytes format. +* `provider_fees` - dictionary which includes provider fees generated when `initialize` endpoint from `Provider` was called. +* `transaction_parameters` - is the configuration `dictionary` for that specific transaction. Usually for `development` we include just the `from` wallet, but for remote networks, you can provide gas fees, required confirmations for that block etc. For more info, check [Brownie docs](https://eth-brownie.readthedocs.io/en/stable/). + +**Returns** + +`str` + +Return value is a hex string for transaction hash which denotes the proof of reusing order. + +**Defined in** + +[models/datatoken.py](https://github.com/oceanprotocol/ocean.py/blob/4aa12afd8a933d64bc2ed68d1e5359d0b9ae62f9/ocean\_lib/models/datatoken.py#LL199C5-L219C10) + +
+ +Source code + +```python + @enforce_types + def reuse_order( + self, + order_tx_id: Union[str, bytes], + provider_fees: dict, + transaction_parameters: dict, + ) -> str: + return self.contract.reuseOrder( + order_tx_id, + ( + checksum_addr(provider_fees["providerFeeAddress"]), + checksum_addr(provider_fees["providerFeeToken"]), + int(provider_fees["providerFeeAmount"]), + provider_fees["v"], + provider_fees["r"], + provider_fees["s"], + provider_fees["validUntil"], + provider_fees["providerData"], + ), + transaction_parameters, + ) +``` + +
diff --git a/developers/ocean.py/technical-details.md b/developers/ocean.py/technical-details.md index 8c438923..816892a0 100644 --- a/developers/ocean.py/technical-details.md +++ b/developers/ocean.py/technical-details.md @@ -529,456 +529,3 @@ A dictionary which contains the following keys (`providerFeeAddress`, `providerF {% endcode %} - -
- -ocean.assets.create_url_asset( self, name: str, url: str, publisher_wallet, wait_for_aqua: bool = True ) -> tuple - -It is the most used functions in all the READMEs. - -Creates asset of type "dataset", having `UrlFiles`, with good defaults. - -It can be called after instantiating Ocean object. - -Params: - -1. `name` - name of the asset, `string` -2. `url` - url that is stored in the asset, `string` -3. `publisher_wallet` - wallet of the asset publisher/owner, `Brownie account` -4. `wait_for_aqua` - boolean value which default is `True`, waiting for aquarius to fetch the asset takes additional time, but if you want to be sure that your asset is indexed, keep the default value. - -Return: - -A tuple which contains the data NFT, datatoken and the data asset. - -{% code overflow="wrap" %} -```python - @enforce_types - def create_url_asset( - self, name: str, url: str, publisher_wallet, wait_for_aqua: bool = True - ) -> tuple: - """Create asset of type "data", having UrlFiles, with good defaults""" - metadata = self._default_metadata(name, publisher_wallet) - files = [UrlFile(url)] - return self._create_1dt(metadata, files, publisher_wallet, wait_for_aqua) -``` -{% endcode %} - -
- -### Datatoken Interface - -Dispenser utils: - -
- -datatoken.dispense(self, amount: Union[int, str], tx_dict: dict) - -This function is used to retrieve funds or datatokens for an user who wants to start an order. - -It is implemented in DatatokenBase, so it can be called within Datatoken class. - -Each parameter has the following meaning: - -1. `amount` - amount of datatokens to be dispensed in wei (int or string format) -2. `tx_dict` - is the configuration `dictionary` for that specific transaction. Usually for `development` we include just the `from` wallet, but for remote networks, you can provide gas fees, required confirmations for that block etc. For more info, check [Brownie docs](https://eth-brownie.readthedocs.io/en/stable/). - -Return value is a hex string which denotes the transaction hash of dispensed datatokens, like a proof. - -```python - @enforce_types - def dispense(self, amount: Union[int, str], tx_dict: dict): - """ - Dispense free tokens via the dispenser faucet. - - :param: amount - number of tokens to dispense, in wei - :tx_dict: e.g. {"from": alice_wallet} - :return: tx - """ - # args for contract tx - datatoken_addr = self.address - from_addr = ( - tx_dict["from"].address - if hasattr(tx_dict["from"], "address") - else tx_dict["from"] - ) - - # do contract tx - tx = self._ocean_dispenser().dispense( - datatoken_addr, amount, from_addr, tx_dict - ) - return tx -``` - -
- -
- -datatoken.dispense_and_order(self, consumer: str, service_index: int, provider_fees: dict, transaction_parameters: dict, consume_market_fees=None) - -This function is used to retrieve funds or datatokens for an user who wants to start an order. - -It is implemented in Datatoken2, so it can be called within Datatoken2 class (using the enterprise template). - -Each parameter has the following meaning: - -1. `consumer` - address of the consumer wallet that needs funding -2. `service_index` - service index as int for identifying the service that you want to further call [`start_order`](https://github.com/oceanprotocol/ocean.py/blob/4aa12afd8a933d64bc2ed68d1e5359d0b9ae62f9/ocean\_lib/models/datatoken.py#LL169C5-L197C10). -3. `transaction_parameters` - is the configuration `dictionary` for that specific transaction. Usually for `development` we include just the `from` wallet, but for remote networks, you can provide gas fees, required confirmations for that block etc. For more info, check [Brownie docs](https://eth-brownie.readthedocs.io/en/stable/). -4. `consume_market_fees` - [`TokenInfo` ](https://github.com/oceanprotocol/ocean.py/blob/4aa12afd8a933d64bc2ed68d1e5359d0b9ae62f9/ocean\_lib/models/datatoken.py#L31)object which contains the consume market fee amount, address & token address. If it is not explicitly specified, by default it has an empty `TokenInfo` object. - -Return value is a hex string which denotes the transaction hash of dispensed datatokens, like a proof of starting order. - -```python -def dispense_and_order( - self, - consumer: str, - service_index: int, - provider_fees: dict, - transaction_parameters: dict, - consume_market_fees=None, - ) -> str: - if not consume_market_fees: - consume_market_fees = TokenFeeInfo() - - buyer_addr = ( - transaction_parameters["from"].address - if hasattr(transaction_parameters["from"], "address") - else transaction_parameters["from"] - ) - - bal = from_wei(self.balanceOf(buyer_addr)) - if bal < 1.0: - dispenser_addr = get_address_of_type(self.config_dict, "Dispenser") - from ocean_lib.models.dispenser import Dispenser # isort: skip - - dispenser = Dispenser(self.config_dict, dispenser_addr) - - # catch key failure modes - st = dispenser.status(self.address) - active, allowedSwapper = st[0], st[6] - if not active: - raise ValueError("No active dispenser for datatoken") - if allowedSwapper not in [ZERO_ADDRESS, buyer_addr]: - raise ValueError(f"Not allowed. allowedSwapper={allowedSwapper}") - - # Try to dispense. If other issues, they'll pop out - dispenser.dispense( - self.address, "1 ether", buyer_addr, transaction_parameters - ) - - return self.start_order( - consumer=ContractBase.to_checksum_address(consumer), - service_index=service_index, - provider_fees=provider_fees, - consume_market_fees=consume_market_fees, - transaction_parameters=transaction_parameters, - ) -``` - -
- -
- -datatoken.dispenser_status(self) -> DispenserStatus - -Returns a `DispenserStatus` object returned from `Dispenser.sol::status(dt_addr)` which is composed of: - -* bool active -* address owner -* bool isMinter -* uint256 maxTokens -* uint256 maxBalance -* uint256 balance -* address allowedSwapper - -These are Solidity return values & types, but `uint256` means int in Python and `address` is a `string` instance. - -For tips & tricks, check [this section](https://github.com/oceanprotocol/ocean.py/blob/4aa12afd8a933d64bc2ed68d1e5359d0b9ae62f9/READMEs/main-flow.md#faucet-tips--tricks) from the [README](https://github.com/oceanprotocol/ocean.py/blob/4aa12afd8a933d64bc2ed68d1e5359d0b9ae62f9/READMEs/main-flow.md). - -It is implemented in DatatokenBase, inherited by Datatoken2, so it can be called within both instances. - -```python -@enforce_types - def dispenser_status(self): - """:return: DispenserStatus object""" - # import here to avoid circular import - from ocean_lib.models.dispenser import DispenserStatus - - status_tup = self._ocean_dispenser().status(self.address) - return DispenserStatus(status_tup) -``` - -
- -Fixed Rate Exchange utils: - -
- -datatoken.create_exchange(self, rate: Union[int, str], base_token_addr: str, tx_dict: dict, owner_addr: Optional[str] = None, publish_market_fee_collector: Optional[str] = None, publish_market_fee: Union[int, str] = 0, with_mint: bool = False, allowed_swapper: str = ZERO_ADDRESS, full_info: bool = False) -> Union[OneExchange, tuple] - -It is implemented in DatatokenBase, inherited by Datatoken2, so it can be called within both instances. - -For this datatoken, create a single fixed-rate exchange (OneExchange). - -This wraps the smart contract method `Datatoken.createFixedRate()` with a simpler interface. - -Main params: - -* `rate` - how many base tokens does 1 datatoken cost? In wei or string -* `base_token_addr` - e.g. OCEAN address -* `tx_dict` - is the configuration `dictionary` for that specific transaction. Usually for `development` we include just the `from` wallet, but for remote networks, you can provide gas fees, required confirmations for that block etc. For more info, check [Brownie docs](https://eth-brownie.readthedocs.io/en/stable/). - -Optional params, with good defaults: - -* `owner_addr` - owner of the datatoken -* `publish_market_fee_collector` - fee going to publish market address -* `publish_market_fee` - in wei or string, e.g. `int(1e15)` or `"0.001 ether"` -* `with_mint` - should the exchange mint datatokens as needed (`True`), or do they need to be supplied/allowed by participants like base token (`False`)? -* `allowed_swapper` - if `ZERO_ADDRESS`, anyone can swap -* `full_info` - return just `OneExchange`, or `(OneExchange, )` - -Return - -* `exchange` - OneExchange -* (maybe) `tx_receipt` - -{% code overflow="wrap" %} -```python -@enforce_types - def create_exchange( - self, - rate: Union[int, str], - base_token_addr: str, - tx_dict: dict, - owner_addr: Optional[str] = None, - publish_market_fee_collector: Optional[str] = None, - publish_market_fee: Union[int, str] = 0, - with_mint: bool = False, - allowed_swapper: str = ZERO_ADDRESS, - full_info: bool = False, - ) -> Union[OneExchange, tuple]: - - # import now, to avoid circular import - from ocean_lib.models.fixed_rate_exchange import OneExchange - - FRE_addr = get_address_of_type(self.config_dict, "FixedPrice") - from_addr = ( - tx_dict["from"].address - if hasattr(tx_dict["from"], "address") - else tx_dict["from"] - ) - BT = Datatoken(self.config_dict, base_token_addr) - owner_addr = owner_addr or from_addr - publish_market_fee_collector = publish_market_fee_collector or from_addr - - tx = self.contract.createFixedRate( - checksum_addr(FRE_addr), - [ - checksum_addr(BT.address), - checksum_addr(owner_addr), - checksum_addr(publish_market_fee_collector), - checksum_addr(allowed_swapper), - ], - [ - BT.decimals(), - self.decimals(), - rate, - publish_market_fee, - with_mint, - ], - tx_dict, - ) - - exchange_id = tx.events["NewFixedRate"]["exchangeId"] - FRE = self._FRE() - exchange = OneExchange(FRE, exchange_id) - if full_info: - return (exchange, tx) - return exchange -``` -{% endcode %} - -
- -
- -datatoken.buy_DT_and_order(self, consumer: str, service_index: int, provider_fees: dict, exchange: Any, transaction_parameters: dict, consume_market_fees=None, ) -> str: - -This function is used to retrieve funds or datatokens for an user who wants to start an order. - -It is implemented in Datatoken class and it is also inherited in Datatoken2 class. - -Each parameter has the following meaning: - -1. `consumer` - address of the consumer wallet that needs funding -2. `service_index` - service index as int for identifying the service that you want to further call [`start_order`](https://github.com/oceanprotocol/ocean.py/blob/4aa12afd8a933d64bc2ed68d1e5359d0b9ae62f9/ocean\_lib/models/datatoken.py#LL169C5-L197C10). -3. `transaction_parameters` - is the configuration `dictionary` for that specific transaction. Usually for `development` we include just the `from` wallet, but for remote networks, you can provide gas fees, required confirmations for that block etc. For more info, check [Brownie docs](https://eth-brownie.readthedocs.io/en/stable/). -4. `consume_market_fees` - [`TokenInfo` ](https://github.com/oceanprotocol/ocean.py/blob/4aa12afd8a933d64bc2ed68d1e5359d0b9ae62f9/ocean\_lib/models/datatoken.py#L31)object which contains the consume market fee amount, address & token address. If it is not explicitly specified, by default it has an empty `TokenInfo` object. - -Return value is a hex string for transaction hash which denotes the proof of starting order. - -```python - @enforce_types - def buy_DT_and_order( - self, - consumer: str, - service_index: int, - provider_fees: dict, - exchange: Any, - transaction_parameters: dict, - consume_market_fees=None, - ) -> str: - fre_address = get_address_of_type(self.config_dict, "FixedPrice") - - # import now, to avoid circular import - from ocean_lib.models.fixed_rate_exchange import OneExchange - - if not consume_market_fees: - consume_market_fees = TokenFeeInfo() - - if not isinstance(exchange, OneExchange): - exchange = OneExchange(fre_address, exchange) - - exchange.buy_DT( - datatoken_amt=to_wei(1), - consume_market_fee_addr=consume_market_fees.address, - consume_market_fee=consume_market_fees.amount, - tx_dict=transaction_parameters, - ) - - return self.start_order( - consumer=ContractBase.to_checksum_address(consumer), - service_index=service_index, - provider_fees=provider_fees, - consume_market_fees=consume_market_fees, - transaction_parameters=transaction_parameters, - ) -``` - -
- -
- -datatoken.get_exchanges(self) -> list - -Returns `List[OneExchange]` - all the exchanges for this datatoken. - -It is implemented in DatatokenBase, inherited by Datatoken2, so it can be called within both instances. - -{% code overflow="wrap" %} -```python -@enforce_types - def get_exchanges(self) -> list: - """return List[OneExchange] - all the exchanges for this datatoken""" - # import now, to avoid circular import - from ocean_lib.models.fixed_rate_exchange import OneExchange - - FRE = self._FRE() - addrs_and_exchange_ids = self.getFixedRates() - exchanges = [ - OneExchange(FRE, exchange_id) for _, exchange_id in addrs_and_exchange_ids - ] - return exchanges - -``` -{% endcode %} - -
- -Orders: - -
- -datatoken.start_order( self, consumer: str, service_index: int, provider_fees: dict, transaction_parameters: dict, consume_market_fees=None, ) -> str - -Starting order of a certain datatoken. - -It is implemented in Datatoken class and it is also inherited in Datatoken2 class. - -Each parameter has the following meaning: - -1. `consumer` - address of the consumer wallet that needs funding -2. `service_index` - service index as int for identifying the service that you want to apply `start_order`. -3. `provider_fees` - dictionary which includes provider fees generated when `initialize` endpoint from `Provider` was called. -4. `transaction_parameters` - is the configuration `dictionary` for that specific transaction. Usually for `development` we include just the `from` wallet, but for remote networks, you can provide gas fees, required confirmations for that block etc. For more info, check [Brownie docs](https://eth-brownie.readthedocs.io/en/stable/). -5. `consume_market_fees` - [`TokenInfo` ](https://github.com/oceanprotocol/ocean.py/blob/4aa12afd8a933d64bc2ed68d1e5359d0b9ae62f9/ocean\_lib/models/datatoken.py#L31)object which contains the consume market fee amount, address & token address. If it is not explicitly specified, by default it has an empty `TokenInfo` object. - -Return value is a hex string for transaction hash which denotes the proof of starting order. - -```python -@enforce_types - def start_order( - self, - consumer: str, - service_index: int, - provider_fees: dict, - transaction_parameters: dict, - consume_market_fees=None, - ) -> str: - - if not consume_market_fees: - consume_market_fees = TokenFeeInfo() - - return self.contract.startOrder( - checksum_addr(consumer), - service_index, - ( - checksum_addr(provider_fees["providerFeeAddress"]), - checksum_addr(provider_fees["providerFeeToken"]), - int(provider_fees["providerFeeAmount"]), - provider_fees["v"], - provider_fees["r"], - provider_fees["s"], - provider_fees["validUntil"], - provider_fees["providerData"], - ), - consume_market_fees.to_tuple(), - transaction_parameters, - ) -``` - -
- -
- -datatoken.reuse_order(self, order_tx_id: Union[str, bytes], provider_fees: dict, transaction_parameters: dict) -> str - -Reusing an order from a certain datatoken. - -It is implemented in Datatoken class and it is also inherited in Datatoken2 class. - -Each parameter has the following meaning: - -1. `order_tx_id` - transaction hash of a previous order, string or bytes format. -2. `provider_fees` - dictionary which includes provider fees generated when `initialize` endpoint from `Provider` was called. -3. `transaction_parameters` - is the configuration `dictionary` for that specific transaction. Usually for `development` we include just the `from` wallet, but for remote networks, you can provide gas fees, required confirmations for that block etc. For more info, check [Brownie docs](https://eth-brownie.readthedocs.io/en/stable/). - -Return value is a hex string for transaction hash which denotes the proof of reusing order. - -```python - @enforce_types - def reuse_order( - self, - order_tx_id: Union[str, bytes], - provider_fees: dict, - transaction_parameters: dict, - ) -> str: - return self.contract.reuseOrder( - order_tx_id, - ( - checksum_addr(provider_fees["providerFeeAddress"]), - checksum_addr(provider_fees["providerFeeToken"]), - int(provider_fees["providerFeeAmount"]), - provider_fees["v"], - provider_fees["r"], - provider_fees["s"], - provider_fees["validUntil"], - provider_fees["providerData"], - ), - transaction_parameters, - ) -``` - -
-