1
0
mirror of https://github.com/oceanprotocol/ocean.js.git synced 2024-11-26 20:39:05 +01:00
ocean.js/docs/classes/Datatoken.md
Alex Coseru 9bf71ba4f0
Features/ethers (#1696)
* add ethers

* global updates

* ve updates

* ve tests

* contract updates

* first test passing

* downgrade to ethers 5.7.2

* add log

* add tx wait

* full NftFactory.test

* add wait

* add Router tests

* fix dispenser

* Nft test

* add dispenser tests

* add fre tests part 1

* WIP datatoken unit tests

* add DFRewards test

* increase gas estimate

* increase gas estimate

* Work datatoken unit tests

* datatoken test more tests

* finished datatoken tests

* fix nft get data

* fix nft transfer tests

* Provider int tests

* Updating CodeExamples.md

* update provider & fix publish flow int test

* wip publish edit consume integration test

* more work on  publish edit consume integration test

* fix edit  publish edit consume integration test

* add 3 int tests

* Updating ComputeExamples.md

* fix signature and download

* fix compute flow integration test

* udapte handleComputeOrder helper

* update datatoken instance

* update datatoken global variable

* mint ocean tokens to consumer as well and added logs

* update compute exammples

* Updating ComputeExamples.md

* wip code examples readme

* update code examples readme

* Updating CodeExamples.md

* run all tests

* update dep in readme

* update readme

* code examples update metadata flags

* update dt instance in code examples md

* set metadata updates

* Updating CodeExamples.md

* update code examples readme structure

* Updating CodeExamples.md

* update readmes table links

* Updating CodeExamples.md

* Updating ComputeExamples.md

* clean-up

* Updating CodeExamples.md

* added missing unit tests for usdc fixed rate exchange tests

* more cleanup and jsdoc updates

* more  jsdoc updates

* donw with jsdoc updates

* handle provider errors

* add missing error handling file

* adds most of the provider errors

* update get compute env return type

* Release 3.0.0-next.0

* adding Typedoc to ethers branch

* update provider signature message

* fix lint

* Release 3.0.0-next.1

* fix lint

* adding Typedoc to ethers branch

* Updating CI to build and commit the documentation

* Updating documentation

* Updating script permissions

* fix todos add missing logic to send tx

* npm package cleanups

* Release 3.0.0-next.2

* update log messages for errors

* Release 3.0.0-next.3

* fix gasFee issue on sendTx

* Release 3.0.0-next.4

* add consume params typings (#1731)

* fix gas fee estimate

* remove comments

* add some delays before resolving datasets

* adds delay to Publish flow tests

* Release 3.0.0-next.5

---------

Co-authored-by: Bogdan Fazakas <bogdan.fazakas@gmail.com>
Co-authored-by: GitHub Actions Bot <>
Co-authored-by: Jamie Hewitt <jamie.hewitt15@gmail.com>
Co-authored-by: Jamie Hewitt <jamie@oceanprotocol.com>
2023-05-29 11:20:38 +03:00

29 KiB

@oceanprotocol/lib / Exports / Datatoken

Class: Datatoken

Hierarchy

Table of contents

Constructors

Properties

Methods

Constructors

constructor

new Datatoken(signer, network?, config?, abi?, abiEnterprise?)

Instantiate Datatoken class

Parameters

Name Type Description
signer Signer The signer object.
network? string | number Network id or name
config? Config The configuration object.
abi? AbiItem[] ABI array of the smart contract
abiEnterprise? AbiItem[] Enterprise ABI array of the smart contract

Overrides

SmartContract.constructor

Defined in

contracts/Datatoken.ts:38

Properties

abi

abi: AbiItem[]

Inherited from

SmartContract.abi

Defined in

contracts/SmartContract.ts:14


abiEnterprise

abiEnterprise: AbiItem[]

Defined in

contracts/Datatoken.ts:23


config

config: Config

Inherited from

SmartContract.config

Defined in

contracts/SmartContract.ts:13


nft

nft: Nft

Defined in

contracts/Datatoken.ts:24


signer

signer: Signer

Inherited from

SmartContract.signer

Defined in

contracts/SmartContract.ts:12

Methods

addMinter

addMinter<G>(dtAddress, address, minter, estimateGas?): Promise<ReceiptOrEstimate<G>>

Add Minter for an ERC20 Datatoken only DatatokenDeployer can succeed

Type parameters

Name Type
G extends boolean = false

Parameters

Name Type Description
dtAddress string Datatoken address
address string caller address
minter string address which is going to be a Minter
estimateGas? G if True, return gas estimate

Returns

Promise<ReceiptOrEstimate<G>>

transactionId

Defined in

contracts/Datatoken.ts:252


addPaymentManager

addPaymentManager<G>(dtAddress, address, paymentManager, estimateGas?): Promise<ReceiptOrEstimate<G>>

Adds a payment manager on a datatoken to a desired address.(can set who's going to collect fee when consuming orders) only DatatokenDeployer can succeed

Type parameters

Name Type
G extends boolean = false

Parameters

Name Type Description
dtAddress string Datatoken address
address string Caller address
paymentManager string The address of the payment manager
estimateGas? G if True, return gas estimate

Returns

Promise<ReceiptOrEstimate<G>>

transactionId

Defined in

contracts/Datatoken.ts:322


amountToUnits

Protected amountToUnits(token, amount, tokenDecimals?): Promise<string>

Converts an amount of tokens to units

Parameters

Name Type Description
token string The token to convert
amount string The amount of tokens to convert
tokenDecimals? number The number of decimals of the token

Returns

Promise<string>

  • The converted amount in units

Inherited from

SmartContract.amountToUnits

Defined in

contracts/SmartContract.ts:43


approve

approve<G>(dtAddress, spender, amount, estimateGas?): Promise<ReceiptOrEstimate<G>>

Approves a spender to spend a certain amount of datatokens.

Type parameters

Name Type
G extends boolean = false

Parameters

Name Type Description
dtAddress string Datatoken address
spender string Spender address
amount string Number of datatokens, as number. Will be converted to wei
estimateGas? G if True, return gas estimate

Returns

Promise<ReceiptOrEstimate<G>>

Defined in

contracts/Datatoken.ts:58


balance

balance(datatokenAddress, address): Promise<string>

Get Address Balance for datatoken

Parameters

Name Type Description
datatokenAddress string -
address string user adress

Returns

Promise<string>

balance Number of datatokens. Will be converted from wei

Defined in

contracts/Datatoken.ts:791


buyFromDispenserAndOrder

buyFromDispenserAndOrder<G>(dtAddress, orderParams, dispenserContract, estimateGas?): Promise<ReceiptOrEstimate<G>>

Gets 1 DT from dispenser and then startsOrder, while burning that DT

Type parameters

Name Type
G extends boolean = false

Parameters

Name Type Description
dtAddress string Datatoken address
orderParams OrderParams The parameters required to place an order.
dispenserContract string dispenser address
estimateGas? G if True, return gas estimate

Returns

Promise<ReceiptOrEstimate<G>>

Defined in

contracts/Datatoken.ts:610


buyFromFreAndOrder

buyFromFreAndOrder<G>(dtAddress, orderParams, freParams, estimateGas?): Promise<ReceiptOrEstimate<G>>

Buys 1 DT from the FRE and then startsOrder, while burning that DT

Type parameters

Name Type
G extends boolean = false

Parameters

Name Type Description
dtAddress string Datatoken address
orderParams OrderParams The parameters required to place an order.
freParams FreOrderParams The parameters required to buy from a fixed-rate exchange.
estimateGas? G if True, return gas estimate

Returns

Promise<ReceiptOrEstimate<G>>

Defined in

contracts/Datatoken.ts:575


cleanPermissions

cleanPermissions<G>(dtAddress, address, estimateGas?): Promise<ReceiptOrEstimate<G>>

Clean Datatoken level Permissions (minters, paymentManager and reset the paymentCollector) for an ERC20 Datatoken Only NFT Owner (at 721 level) can call it.

Type parameters

Name Type
G extends boolean = false

Parameters

Name Type Description
dtAddress string Datatoken address where we want to clean permissions
address string User adress
estimateGas? G if True, return gas estimate

Returns

Promise<ReceiptOrEstimate<G>>

transactionId

Defined in

contracts/Datatoken.ts:680


createDispenser

createDispenser<G>(dtAddress, address, dispenserAddress, dispenserParams, estimateGas?): Promise<ReceiptOrEstimate<G>>

Creates a new Dispenser

Type parameters

Name Type
G extends boolean = false

Parameters

Name Type Description
dtAddress string Datatoken address
address string Caller address
dispenserAddress string Dispenser contract address
dispenserParams DispenserParams The parameters required to create a dispenser contract.
estimateGas? G if True, return gas estimate

Returns

Promise<ReceiptOrEstimate<G>>

transactionId

Defined in

contracts/Datatoken.ts:157


createFixedRate

createFixedRate<G>(dtAddress, address, fixedRateParams, estimateGas?): Promise<ReceiptOrEstimate<G>>

Creates a new FixedRateExchange setup.

Type parameters

Name Type
G extends boolean = false

Parameters

Name Type Description
dtAddress string Datatoken address
address string Caller address
fixedRateParams FreCreationParams The parameters required to create a fixed-rate exchange contract.
estimateGas? G if True, return gas estimate

Returns

Promise<ReceiptOrEstimate<G>>

Defined in

contracts/Datatoken.ts:91


getCap

getCap(dtAddress): Promise<string>

Returns the Datatoken cap

Parameters

Name Type Description
dtAddress string Datatoken adress

Returns

Promise<string>

Defined in

contracts/Datatoken.ts:723


getContract

Protected getContract(address, abi?): Contract

Returns a contract instance for the given address

Parameters

Name Type Description
address string The address of the contract
abi? AbiItem[] The ABI of the contract

Returns

Contract

  • The contract instance

Inherited from

SmartContract.getContract

Defined in

contracts/SmartContract.ts:80


getDecimals

getDecimals(dtAddress): Promise<number>

It returns the token decimals, how many supported decimal points

Parameters

Name Type Description
dtAddress string Datatoken adress

Returns

Promise<number>

Defined in

contracts/Datatoken.ts:734


getDefaultAbi

getDefaultAbi(): AbiItem[]

Returns

AbiItem[]

Overrides

SmartContract.getDefaultAbi

Defined in

contracts/Datatoken.ts:26


getFairGasPrice

Protected getFairGasPrice(): Promise<string>

Retruns the gas price

Returns

Promise<string>

  • The fair gas price

Inherited from

SmartContract.getFairGasPrice

Defined in

contracts/SmartContract.ts:70


getFreOrderParams

Private getFreOrderParams(freParams): Promise<any>

Parameters

Name Type
freParams FreOrderParams

Returns

Promise<any>

Defined in

contracts/Datatoken.ts:859


getNFTAddress

getNFTAddress(dtAddress): Promise<string>

It returns the token decimals, how many supported decimal points

Parameters

Name Type Description
dtAddress string Datatoken adress

Returns

Promise<string>

Defined in

contracts/Datatoken.ts:767


getName

getName(dtAddress): Promise<string>

It returns the name of the token

Parameters

Name Type Description
dtAddress string Datatoken adress

Returns

Promise<string>

Defined in

contracts/Datatoken.ts:756


getPaymentCollector

getPaymentCollector(dtAddress): Promise<string>

getPaymentCollector - It returns the current paymentCollector

Parameters

Name Type Description
dtAddress string datatoken address

Returns

Promise<string>

Defined in

contracts/Datatoken.ts:429


getPermissions

getPermissions(dtAddress, address): Promise<DatatokenRoles>

Returns ERC20 Datatoken user's permissions for a datatoken

Parameters

Name Type Description
dtAddress string Datatoken adress
address string user adress

Returns

Promise<DatatokenRoles>

Defined in

contracts/Datatoken.ts:709


getPublishingMarketFee

getPublishingMarketFee(datatokenAddress): Promise<PublishingMarketFee>

Returns the current fee set by the publishing market

Parameters

Name Type Description
datatokenAddress string Datatoken adress

Returns

Promise<PublishingMarketFee>

Current fee set by the publishing market

Defined in

contracts/Datatoken.ts:845


getSymbol

getSymbol(dtAddress): Promise<string>

It returns the token symbol

Parameters

Name Type Description
dtAddress string Datatoken adress

Returns

Promise<string>

Defined in

contracts/Datatoken.ts:745


isDatatokenDeployer

isDatatokenDeployer(dtAddress, address): Promise<boolean>

Returns true if address has deployERC20 role

Parameters

Name Type Description
dtAddress string Datatoken adress
address string -

Returns

Promise<boolean>

Defined in

contracts/Datatoken.ts:779


mint

mint<G>(dtAddress, address, amount, toAddress?, estimateGas?): Promise<ReceiptOrEstimate<G>>

Mints datatokens

Type parameters

Name Type
G extends boolean = false

Parameters

Name Type Description
dtAddress string Datatoken address
address string Minter address
amount string Number of datatokens, as number. Will be converted to wei
toAddress? string only if toAddress is different from the minter
estimateGas? G if True, return gas estimate

Returns

Promise<ReceiptOrEstimate<G>>

transactionId

Defined in

contracts/Datatoken.ts:208


removeMinter

removeMinter<G>(dtAddress, address, minter, estimateGas?): Promise<ReceiptOrEstimate<G>>

Revoke Minter permission for an ERC20 Datatoken only DatatokenDeployer can succeed

Type parameters

Name Type
G extends boolean = false

Parameters

Name Type Description
dtAddress string Datatoken address
address string caller address
minter string address which will have removed the Minter permission
estimateGas? G if True, return gas estimate

Returns

Promise<ReceiptOrEstimate<G>>

Defined in

contracts/Datatoken.ts:287


removePaymentManager

removePaymentManager<G>(dtAddress, address, paymentManager, estimateGas?): Promise<ReceiptOrEstimate<G>>

Revoke paymentManager permission for an ERC20 Datatoken only DatatokenDeployer can succeed

Type parameters

Name Type
G extends boolean = false

Parameters

Name Type Description
dtAddress string Datatoken address
address string User address
paymentManager string User which will be removed from paymentManager permission
estimateGas? G if True, return gas estimate

Returns

Promise<ReceiptOrEstimate<G>>

trxReceipt

Defined in

contracts/Datatoken.ts:357


reuseOrder

reuseOrder<G>(dtAddress, orderTxId, providerFees, estimateGas?): Promise<ReceiptOrEstimate<G>>

Reuse Order: called by payer or consumer having a valid order, but with expired provider access. Pays the provider fee again, but it will not require a new datatoken payment Requires previous approval of provider fee.

Type parameters

Name Type
G extends boolean = false

Parameters

Name Type Description
dtAddress string Datatoken address
orderTxId string previous valid order
providerFees ProviderFees provider fees
estimateGas? G if True, return gas estimate

Returns

Promise<ReceiptOrEstimate<G>>

string

Defined in

contracts/Datatoken.ts:545


setData

setData<G>(dtAddress, address, value, estimateGas?): Promise<ReceiptOrEstimate<G>>

setData This function allows to store data with a preset key (keccak256(dtAddress)) into NFT 725 Store only DatatokenDeployer can succeed

Type parameters

Name Type
G extends boolean = false

Parameters

Name Type Description
dtAddress string Datatoken address
address string User address
value string Data to be stored into 725Y standard
estimateGas? G if True, return gas estimate

Returns

Promise<ReceiptOrEstimate<G>>

transactionId

Defined in

contracts/Datatoken.ts:644


setPaymentCollector

setPaymentCollector<G>(dtAddress, address, paymentCollector, estimateGas?): Promise<ReceiptOrEstimate<G>>

This function allows to set a new PaymentCollector (receives DT when consuming) If not set the paymentCollector is the NFT Owner only NFT owner can call

Type parameters

Name Type
G extends boolean = false

Parameters

Name Type Description
dtAddress string Datatoken address
address string Caller address
paymentCollector string User to be set as new payment collector
estimateGas? G if True, return gas estimate

Returns

Promise<ReceiptOrEstimate<G>>

trxReceipt

Defined in

contracts/Datatoken.ts:393


setPublishingMarketFee

setPublishingMarketFee<G>(datatokenAddress, publishMarketFeeAddress, publishMarketFeeToken, publishMarketFeeAmount, address, estimateGas?): Promise<ReceiptOrEstimate<G>>

Allows to set the fee required by the publisherMarket only publishMarketFeeAddress can call it

Type parameters

Name Type
G extends boolean = false

Parameters

Name Type Description
datatokenAddress string Datatoken adress
publishMarketFeeAddress string new publish Market Fee Address
publishMarketFeeToken string new publish Market Fee Token
publishMarketFeeAmount string new fee amount
address string user adress
estimateGas? G if True, return gas estimate

Returns

Promise<ReceiptOrEstimate<G>>

Defined in

contracts/Datatoken.ts:807


startOrder

startOrder<G>(dtAddress, consumer, serviceIndex, providerFees, consumeMarketFee?, estimateGas?): Promise<ReceiptOrEstimate<G>>

Start Order: called by payer or consumer prior ordering a service consume on a marketplace.

Type parameters

Name Type
G extends boolean = false

Parameters

Name Type Description
dtAddress string Datatoken address
consumer string Consumer Address
serviceIndex number Service index in the metadata
providerFees ProviderFees provider fees
consumeMarketFee? ConsumeMarketFee -
estimateGas? G if True, return gas estimate

Returns

Promise<ReceiptOrEstimate<G>>

string

Defined in

contracts/Datatoken.ts:497


transfer

transfer<G>(dtAddress, toAddress, amount, estimateGas?): Promise<ReceiptOrEstimate<G>>

Transfer tokens(as number) from address to toAddress

Type parameters

Name Type
G extends boolean = false

Parameters

Name Type Description
dtAddress string Datatoken address
toAddress string Receiver address
amount string Number of datatokens, as number. Will be converted to wei.
estimateGas? G if True, return gas estimate

Returns

Promise<ReceiptOrEstimate<G>>

transactionId

Defined in

contracts/Datatoken.ts:443


transferWei

transferWei<G>(dtAddress, toAddress, amount, estimateGas?): Promise<ReceiptOrEstimate<G>>

Transfer in wei from address to toAddress

Type parameters

Name Type
G extends boolean = false

Parameters

Name Type Description
dtAddress string Datatoken address
toAddress string Receiver address
amount string Number of datatokens (number) expressed as wei
estimateGas? G if True, return gas estimate

Returns

Promise<ReceiptOrEstimate<G>>

transactionId

Defined in

contracts/Datatoken.ts:465


unitsToAmount

Protected unitsToAmount(token, amount, tokenDecimals?): Promise<string>

Converts an amount of units to tokens

Parameters

Name Type Description
token string The token to convert
amount string The amount of units to convert
tokenDecimals? number The number of decimals in the token

Returns

Promise<string>

  • The converted amount in tokens

Inherited from

SmartContract.unitsToAmount

Defined in

contracts/SmartContract.ts:58