Datatoken Interface Tech Details

Technical details about Datatoken functions

Datatoken contract interface is like the superhero that kicks off the action-packed adventure of contract calls! It's here to save the day by empowering us to unleash the mighty powers of dispensers, fixed rate exchanges, and initializing orders. For this page, we present the utilitary functions that embark you on the Ocean journey.

Create Dispenser

  • create_dispenser(self, tx_dict: dict, max_tokens: Optional[Union[int, str]] = None, max_balance: Optional[Union[int, str]] = None, with_mint: Optional[bool] = True)

Through datatoken, you can deploy a new dispenser schema which is used for creating free assets, because its behaviour is similar with a faucet. β›²

It is implemented in DatatokenBase, inherited by Datatoken2, so it can be called within both instances.

Parameters

  • 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.

  • max_tokens - maximum amount of tokens to dispense in wei. The default is a large number.

  • max_balance - maximum balance of requester in wei. The default is a large number.

  • with_mint - boolean, true if we want to allow the dispenser to be a minter as default value

Returns

str

Return value is a hex string which denotes the transaction hash of dispenser deployment.

Defined in

models/datatoken.py

Source code
@enforce_types
    def create_dispenser(
        self,
        tx_dict: dict,
        max_tokens: Optional[Union[int, str]] = None,
        max_balance: Optional[Union[int, str]] = None,
        with_mint: Optional[bool] = True,
    ):
        """
        For this datataken, create a dispenser faucet for free tokens.

        This wraps the smart contract method Datatoken.createDispenser()
          with a simpler interface.

        :param: max_tokens - max # tokens to dispense, in wei
        :param: max_balance - max balance of requester
        :tx_dict: e.g. {"from": alice_wallet}
        :return: tx
        """
        # already created, so nothing to do
        if self.dispenser_status().active:
            return

        # set max_tokens, max_balance if needed
        max_tokens = max_tokens or MAX_UINT256
        max_balance = max_balance or MAX_UINT256

        # args for contract tx
        dispenser_addr = get_address_of_type(self.config_dict, "Dispenser")
        with_mint = with_mint  # True -> can always mint more
        allowed_swapper = ZERO_ADDRESS  # 0 -> so anyone can call dispense

        # do contract tx
        tx = self.createDispenser(
            dispenser_addr,
            max_tokens,
            max_balance,
            with_mint,
            allowed_swapper,
            tx_dict,
        )
        return tx

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.

Returns

str

Return value is a hex string which denotes the transaction hash of dispensed datatokens, like a proof.

Defined in

models/datatoken.py

Source code

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.

  • 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.

  • consume_market_fees - TokenInfo 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

Source code

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 from the README.

It is implemented in DatatokenBase, inherited by Datatoken2, so it can be called within both instances.

Defined in

models/datatoken.py

Source code

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, 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.

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"

  • allowed_swapper - if ZERO_ADDRESS, anyone can swap

  • full_info - return just OneExchange, or (OneExchange, <other info>)

Returns

  • exchange - OneExchange

  • (maybe) tx_receipt

Defined in

models/datatoken.py

Source code

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.

  • 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.

  • consume_market_fees - TokenInfo 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

Source code

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

Source code

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.

  • consume_market_fees - TokenInfo 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

Source code

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.

Returns

str

Return value is a hex string for transaction hash which denotes the proof of reusing order.

Defined in

models/datatoken.py

Source code

Last updated

Was this helpful?