1
0
mirror of https://github.com/oceanprotocol/ocean.js.git synced 2024-11-26 20:39:05 +01:00
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

25 KiB

@oceanprotocol/lib / Exports / Nft

Class: Nft

Hierarchy

Table of contents

Constructors

Properties

Methods

Constructors

constructor

new Nft(signer, network?, config?, abi?)

Instantiate the smart contract.

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

Inherited from

SmartContract.constructor

Defined in

contracts/SmartContract.ts:25

Properties

abi

abi: AbiItem[]

Inherited from

SmartContract.abi

Defined in

contracts/SmartContract.ts:14


config

config: Config

Inherited from

SmartContract.config

Defined in

contracts/SmartContract.ts:13


signer

signer: Signer

Inherited from

SmartContract.signer

Defined in

contracts/SmartContract.ts:12

Methods

addDatatokenDeployer

addDatatokenDeployer<G>(nftAddress, address, datatokenDeployer, estimateGas?): Promise<ReceiptOrEstimate<G>>

Add DatatokenDeployer permission - only Manager can succeed

Type parameters

Name Type
G extends boolean = false

Parameters

Name Type Description
nftAddress string NFT contract address
address string NFT Manager adress
datatokenDeployer string User adress which is going to have DatatokenDeployer permission
estimateGas? G if True, return gas estimate

Returns

Promise<ReceiptOrEstimate<G>>

trxReceipt

Defined in

contracts/NFT.ts:169


addManager

addManager<G>(nftAddress, address, manager, estimateGas?): Promise<ReceiptOrEstimate<G>>

Add Manager for NFT Contract (only NFT Owner can succeed)

Type parameters

Name Type
G extends boolean = false

Parameters

Name Type Description
nftAddress string NFT contract address
address string NFT Owner adress
manager string User adress which is going to be assing manager
estimateGas? G if True, return gas estimate

Returns

Promise<ReceiptOrEstimate<G>>

trxReceipt

Defined in

contracts/NFT.ts:101


addMetadataUpdater

addMetadataUpdater<G>(nftAddress, address, metadataUpdater, estimateGas?): Promise<ReceiptOrEstimate<G>>

Add Metadata Updater permission - only Manager can succeed

Type parameters

Name Type
G extends boolean = false

Parameters

Name Type Description
nftAddress string NFT contract address
address string NFT Manager adress
metadataUpdater string User adress which is going to have Metadata Updater permission
estimateGas? G if True, return gas estimate

Returns

Promise<ReceiptOrEstimate<G>>

trxReceipt

Defined in

contracts/NFT.ts:243


addStoreUpdater

addStoreUpdater<G>(nftAddress, address, storeUpdater, estimateGas?): Promise<ReceiptOrEstimate<G>>

Add Store Updater permission - only Manager can succeed

Type parameters

Name Type
G extends boolean = false

Parameters

Name Type Description
nftAddress string NFT contract address
address string NFT Manager adress
storeUpdater string User adress which is going to have Store Updater permission
estimateGas? G if True, return gas estimate

Returns

Promise<ReceiptOrEstimate<G>>

trxReceipt

Defined in

contracts/NFT.ts:313


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


cleanPermissions

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

This function allows to remove all ROLES at NFT level: Managers, DatatokenDeployer, MetadataUpdater, StoreUpdater Even NFT Owner has to readd himself as Manager Permissions at Datatoken level stay. Only NFT Owner can call it.

Type parameters

Name Type
G extends boolean = false

Parameters

Name Type Description
nftAddress string NFT contract address
address string NFT Owner adress
estimateGas? G if True, return gas estimate

Returns

Promise<ReceiptOrEstimate<G>>

trxReceipt

Defined in

contracts/NFT.ts:387


createDatatoken

createDatatoken<G>(nftAddress, address, minter, paymentCollector, mpFeeAddress, feeToken, feeAmount, cap, name?, symbol?, templateIndex?, estimateGas?): Promise<G extends false ? string : BigNumber>

Create new ERC20 Datatoken - only user with DatatokenDeployer permission can succeed

Type parameters

Name Type
G extends boolean = false

Parameters

Name Type Description
nftAddress string NFT address
address string User address
minter string User set as initial minter for the Datatoken
paymentCollector string initial paymentCollector for this DT
mpFeeAddress string Consume marketplace fee address
feeToken string address of the token marketplace wants to add fee on top
feeAmount string amount of feeToken to be transferred to mpFeeAddress on top, will be converted to WEI
cap string Maximum cap (Number) - will be converted to wei
name? string Token name
symbol? string Token symbol
templateIndex? number NFT template index
estimateGas? G if True, return gas estimate

Returns

Promise<G extends false ? string : BigNumber>

ERC20 Datatoken address

Defined in

contracts/NFT.ts:34


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


getData

getData(nftAddress, key): Promise<string>

Gets stored data at a given key in an NFT

Parameters

Name Type Description
nftAddress string The address of the NFT.
key string The key of the data to get.

Returns

Promise<string>

The data stored at the key

Defined in

contracts/NFT.ts:753


getDefaultAbi

getDefaultAbi(): AbiItem[]

Returns

AbiItem[]

Overrides

SmartContract.getDefaultAbi

Defined in

contracts/NFT.ts:14


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


getMetadata

getMetadata(nftAddress): Promise<Object>

Returns Metadata details for an NFT

Parameters

Name Type Description
nftAddress string NFT contract address

Returns

Promise<Object>

Defined in

contracts/NFT.ts:687


getNftOwner

getNftOwner(nftAddress): Promise<string>

Get NFT Owner

Parameters

Name Type Description
nftAddress string NFT contract address

Returns

Promise<string>

string

Defined in

contracts/NFT.ts:664


getNftPermissions

getNftPermissions(nftAddress, address): Promise<NftRoles>

Gets NFT Permissions for a specified user

Parameters

Name Type Description
nftAddress string NFT contract address
address string user adress

Returns

Promise<NftRoles>

Defined in

contracts/NFT.ts:676


getTokenURI

getTokenURI(nftAddress, id): Promise<string>

Gets the token URI of an NFT.

Parameters

Name Type Description
nftAddress string The address of the NFT.
id number The ID of the token.

Returns

Promise<string>

Defined in

contracts/NFT.ts:766


isDatatokenDeployer

isDatatokenDeployer(nftAddress, address): Promise<boolean>

Checks if user has DatatokenDeployer role

Parameters

Name Type Description
nftAddress string NFT contract address
address string user adress

Returns

Promise<boolean>

Defined in

contracts/NFT.ts:698


removeDatatokenDeployer

removeDatatokenDeployer<G>(nftAddress, address, datatokenDeployer, estimateGas?): Promise<ReceiptOrEstimate<G>>

Remove DatatokenDeployer permission - only Manager can succeed

Type parameters

Name Type
G extends boolean = false

Parameters

Name Type Description
nftAddress string NFT contract address
address string NFT Manager adress
datatokenDeployer string Address of the user to be revoked DatatokenDeployer Permission
estimateGas? G if True, return gas estimate

Returns

Promise<ReceiptOrEstimate<G>>

trxReceipt

Defined in

contracts/NFT.ts:204


removeManager

removeManager<G>(nftAddress, address, manager, estimateGas?): Promise<ReceiptOrEstimate<G>>

Removes a specific manager for NFT Contract (only NFT Owner can succeed)

Type parameters

Name Type
G extends boolean = false

Parameters

Name Type Description
nftAddress string NFT contract address
address string NFT Owner adress
manager string User adress which is going to be removed as manager
estimateGas? G if True, return gas estimate

Returns

Promise<ReceiptOrEstimate<G>>

trxReceipt

Defined in

contracts/NFT.ts:135


removeMetadataUpdater

removeMetadataUpdater<G>(nftAddress, address, metadataUpdater, estimateGas?): Promise<ReceiptOrEstimate<G>>

Remove Metadata Updater permission - only Manager can succeed

Type parameters

Name Type
G extends boolean = false

Parameters

Name Type Description
nftAddress string NFT contract address
address string NFT Manager adress
metadataUpdater string Address of the user to be revoked Metadata updater Permission
estimateGas? G if True, return gas estimate

Returns

Promise<ReceiptOrEstimate<G>>

trxReceipt

Defined in

contracts/NFT.ts:276


removeStoreUpdater

removeStoreUpdater<G>(nftAddress, address, storeUpdater, estimateGas?): Promise<ReceiptOrEstimate<G>>

Remove Store Updater permission - only Manager can succeed

Type parameters

Name Type
G extends boolean = false

Parameters

Name Type Description
nftAddress string NFT contract address
address string NFT Manager adress
storeUpdater string Address of the user to be revoked Store Updater Permission
estimateGas? G if True, return gas estimate

Returns

Promise<ReceiptOrEstimate<G>>

trxReceipt

Defined in

contracts/NFT.ts:347


safeTransferNft

safeTransferNft<G>(nftAddress, nftOwner, nftReceiver, tokenId?, estimateGas?): Promise<ReceiptOrEstimate<G>>

safeTransferNFT Used for transferring the NFT, can be used by an approved relayer will clean all permissions both on NFT and Datatoken level.

Type parameters

Name Type
G extends boolean = false

Parameters

Name Type Description
nftAddress string NFT contract address
nftOwner string Current NFT Owner adress
nftReceiver string User which will receive the NFT, will also be set as Manager
tokenId? number The id of the token to be transfered
estimateGas? G if True, return gas estimate

Returns

Promise<ReceiptOrEstimate<G>>

trxReceipt

Defined in

contracts/NFT.ts:466


setData

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

Allows users to store data with a preset key (keccak256(ERC20Address)) into NFT 725 Store only ERC20Deployer can succeed

Type parameters

Name Type
G extends boolean = false

Parameters

Name Type Description
nftAddress string Nft datatoken adress
address string User adress
key string Key of the data to be stored into 725Y standard
value string Data to be stored into 725Y standard
estimateGas? G if True, return gas estimate

Returns

Promise<ReceiptOrEstimate<G>>

transactionId

Defined in

contracts/NFT.ts:717


setMetadata

setMetadata<G>(nftAddress, address, metadataState, metadataDecryptorUrl, metadataDecryptorAddress, flags, data, metadataHash, metadataProofs?, estimateGas?): Promise<ReceiptOrEstimate<G>>

Creates or update Metadata cached by Aquarius. Also, updates the METADATA_DECRYPTOR key

Type parameters

Name Type
G extends boolean = false

Parameters

Name Type Description
nftAddress string NFT contract address
address string Caller address NFT Owner adress
metadataState number
metadataDecryptorUrl string
metadataDecryptorAddress string
flags string
data string
metadataHash string
metadataProofs? MetadataProof[]
estimateGas? G if True, return gas estimate

Returns

Promise<ReceiptOrEstimate<G>>

trxReceipt

Defined in

contracts/NFT.ts:515


setMetadataAndTokenURI

setMetadataAndTokenURI<G>(nftAddress, metadataUpdater, metadataAndTokenURI, estimateGas?): Promise<ReceiptOrEstimate<G>>

Helper function to improve UX sets both MetaData & TokenURI in one tx

Type parameters

Name Type
G extends boolean = false

Parameters

Name Type Description
nftAddress string NFT contract address
metadataUpdater string -
metadataAndTokenURI MetadataAndTokenURI metaDataAndTokenURI object
estimateGas? G if True, return gas estimate

Returns

Promise<ReceiptOrEstimate<G>>

trxReceipt

Defined in

contracts/NFT.ts:568


setMetadataState

setMetadataState<G>(nftAddress, address, metadataState, estimateGas?): Promise<ReceiptOrEstimate<G>>

setMetadataState Used for updating the metadata State

Type parameters

Name Type
G extends boolean = false

Parameters

Name Type Description
nftAddress string NFT contract address
address string Caller address => metadata updater
metadataState number new metadata state
estimateGas? G if True, return gas estimate

Returns

Promise<ReceiptOrEstimate<G>>

trxReceipt

Defined in

contracts/NFT.ts:606


setTokenURI

setTokenURI<G>(nftAddress, data, estimateGas?): Promise<ReceiptOrEstimate<G>>

set TokenURI on an nft

Type parameters

Name Type
G extends boolean = false

Parameters

Name Type Description
nftAddress string NFT contract address
data string input data for TokenURI
estimateGas? G if True, return gas estimate

Returns

Promise<ReceiptOrEstimate<G>>

transaction receipt

Defined in

contracts/NFT.ts:638


transferNft

transferNft<G>(nftAddress, nftOwner, nftReceiver, tokenId?, estimateGas?): Promise<ReceiptOrEstimate<G>>

Transfers the NFT will clean all permissions both on NFT and Datatoken level.

Type parameters

Name Type
G extends boolean = false

Parameters

Name Type Description
nftAddress string NFT contract address
nftOwner string Current NFT Owner adress
nftReceiver string User which will receive the NFT, will also be set as Manager
tokenId? number The id of the token to be transfered
estimateGas? G if True, return gas estimate

Returns

Promise<ReceiptOrEstimate<G>>

trxReceipt

Defined in

contracts/NFT.ts:421


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