Skip to content

Commit

Permalink
Fix #1222: Fee objects, to make fees less cumbersome (#1220)
Browse files Browse the repository at this point in the history
  • Loading branch information
calina-c authored Dec 26, 2022
1 parent d6f6a90 commit 68cd010
Show file tree
Hide file tree
Showing 27 changed files with 413 additions and 465 deletions.
2 changes: 1 addition & 1 deletion READMEs/key-value-flow.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Ensure that you've already (a) [installed Ocean](install.md), and (b) [set up lo

In Python console:
```python
from ocean_lib.models.arguments import DataNFTArguments
from ocean_lib.models.data_nft import DataNFTArguments
data_nft = ocean.data_nft_factory.create(DataNFTArguments('NFT1', 'NFT1'), alice)
```

Expand Down
12 changes: 6 additions & 6 deletions READMEs/main-flow.md
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ url_file = UrlFile(
)

# Publish data asset
from ocean_lib.ocean.ocean_assets import DatatokenArguments
from ocean_lib.models.datatoken import DatatokenArguments
_, _, ddo = ocean.assets.create(
metadata,
alice,
Expand All @@ -239,7 +239,7 @@ You can control this during create():

Calling `create()` like above generates a data NFT, a datatoken for that NFT, and a ddo. This is the most common case. However, sometimes you may want _just_ the data NFT, e.g. if using a data NFT as a simple key-value store. Here's how:
```python
from ocean_lib.models.arguments import DataNFTArguments
from ocean_lib.models.data_nft import DataNFTArguments
data_nft = ocean.data_nft_factory.create(DataNFTArguments('NFT1', 'NFT1'), alice)
```

Expand All @@ -250,7 +250,7 @@ If you call `create()` after this, you can pass in an argument `data_nft_address
Calling `create()` like above generates a data NFT, a datatoken for that NFT, and a ddo object. However, we may want a second datatoken. Or, we may have started with _just_ the data NFT, and want to add a datatoken to it. Here's how:

```python
from ocean_lib.models.arguments import DatatokenArguments
from ocean_lib.models.datatoken import DatatokenArguments
datatoken = data_nft.create_datatoken(DatatokenArguments("Datatoken 1", "DT1"), alice)
```

Expand Down Expand Up @@ -309,7 +309,7 @@ To learn more about the exchange status:

```python
print(exchange.details)
print(exchange.fees_info)
print(exchange.exchange_fees_info)
```

It will output something like:
Expand All @@ -329,8 +329,8 @@ ExchangeDetails:
bt_decimals = 18
owner = 0x02354A1F160A3fd7ac8b02ee91F04104440B28E7

>>> print(exchange.fees_info)
FeesInfo:
>>> print(exchange.exchange_fees_info)
ExchangeFeeInfo:
publish_market_fee = 0.0 (0 wei)
publish_market_fee_available = 0.0 (0 wei)
publish_market_fee_collector = 0x02354A1F160A3fd7ac8b02ee91F04104440B28E7
Expand Down
2 changes: 1 addition & 1 deletion READMEs/profile-nfts-flow.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ We publish a data NFT like elsewhere, except we set `transferable=False` (and sk
In the Python console:
```python
# Publish an NFT token. Note "transferable=False"
from ocean_lib.models.arguments import DataNFTArguments
from ocean_lib.models.data_nft import DataNFTArguments
data_nft = ocean.data_nft_factory.create(DataNFTArguments('NFT1', 'NFT1', transferable=False), alice)
```

Expand Down
9 changes: 6 additions & 3 deletions ocean_lib/assets/test/test_asset_downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from ocean_lib.assets.asset_downloader import download_asset_files, is_consumable
from ocean_lib.assets.ddo import DDO
from ocean_lib.data_provider.data_service_provider import DataServiceProvider
from ocean_lib.models.datatoken import TokenFeeInfo
from ocean_lib.services.service import Service
from tests.resources.ddo_helpers import (
get_first_service_by_type,
Expand Down Expand Up @@ -166,14 +167,16 @@ def test_ocean_assets_download_destination_file(
)

provider_fees = initialize_response.json()["providerFee"]
consume_market_fees = TokenFeeInfo(
address=publisher_wallet.address,
token=datatoken.address,
)

receipt = datatoken.start_order(
consumer=publisher_wallet.address,
service_index=ddo.get_index_of_service(access_service),
provider_fees=provider_fees,
consume_market_order_fee_address=publisher_wallet.address,
consume_market_order_fee_token=datatoken.address,
consume_market_order_fee_amount=0,
consume_market_fees=consume_market_fees,
transaction_parameters={"from": publisher_wallet},
)

Expand Down
166 changes: 0 additions & 166 deletions ocean_lib/models/arguments.py

This file was deleted.

71 changes: 64 additions & 7 deletions ocean_lib/models/data_nft.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@
# Copyright 2022 Ocean Protocol Foundation
# SPDX-License-Identifier: Apache-2.0
#
import warnings
from enum import IntEnum, IntFlag
from typing import Optional

from enforce_typing import enforce_types

from ocean_lib.models.datatoken import Datatoken
from ocean_lib.ocean.util import get_address_of_type
from ocean_lib.web3_internal.constants import ZERO_ADDRESS
from ocean_lib.web3_internal.contract_base import ContractBase


Expand Down Expand Up @@ -41,11 +45,64 @@ class DataNFT(ContractBase):
def create_datatoken(self, datatoken_args, wallet) -> Datatoken:
return datatoken_args.create_datatoken(self, wallet)

# TODO
# def ZERO ADDRESS
# if publish_market_order_fee_address is None:
# publish_market_order_fee_address = from_address

# def Ocean address
# if publish_market_order_fee_token is None:
# publish_market_order_fee_token = ZERO_ADDRESS
class DataNFTArguments:
def __init__(
self,
name: str,
symbol: str,
template_index: Optional[int] = 1,
additional_datatoken_deployer: Optional[str] = None,
additional_metadata_updater: Optional[str] = None,
uri: Optional[str] = None,
transferable: Optional[bool] = None,
owner: Optional[str] = None,
):
"""
:param name: str name of data NFT if creating a new one
:param symbol: str symbol of data NFT if creating a new one
:param template_index: int template index of the data NFT, by default is 1.
:param additional_datatoken_deployer: str address of an additional ERC20 deployer.
:param additional_metadata_updater: str address of an additional metadata updater.
:param uri: str URL of the data NFT.
"""
self.name = name
self.symbol = symbol or name
self.template_index = template_index
self.additional_datatoken_deployer = (
additional_datatoken_deployer or ZERO_ADDRESS
)
self.additional_metadata_updater = additional_metadata_updater or ZERO_ADDRESS
self.uri = uri or "https://oceanprotocol.com/nft/"
self.transferable = transferable or True
self.owner = owner

def deploy_contract(self, config_dict, wallet) -> DataNFT:
from ocean_lib.models.data_nft_factory import ( # isort:skip
DataNFTFactoryContract,
)

address = get_address_of_type(config_dict, DataNFTFactoryContract.CONTRACT_NAME)
data_nft_factory = DataNFTFactoryContract(config_dict, address)

receipt = data_nft_factory.deployERC721Contract(
self.name,
self.symbol,
self.template_index,
self.additional_metadata_updater,
self.additional_datatoken_deployer,
self.uri,
self.transferable,
self.owner or wallet.address,
{"from": wallet},
)

with warnings.catch_warnings():
warnings.filterwarnings(
"ignore",
message=".*Event log does not contain enough topics for the given ABI.*",
)
registered_event = receipt.events["NFTCreated"]

data_nft_address = registered_event["newTokenAddress"]
return DataNFT(config_dict, data_nft_address)
Loading

0 comments on commit 68cd010

Please sign in to comment.