@oceanprotocol/lib 4.3.3 → 5.0.0-next.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -4,7 +4,9 @@ All notable changes to this project will be documented in this file. Dates are d
4
4
 
5
5
  Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
6
6
 
7
- #### [v4.3.3](https://github.com/oceanprotocol/ocean.js/compare/v5.0.0-next.1...v4.3.3)
7
+ #### [v5.0.0-next.2](https://github.com/oceanprotocol/ocean.js/compare/v5.0.0-next.1...v5.0.0-next.2)
8
+
9
+ - Feature/contracts_240 [`#1979`](https://github.com/oceanprotocol/ocean.js/pull/1979)
8
10
 
9
11
  #### [v5.0.0-next.1](https://github.com/oceanprotocol/ocean.js/compare/v4.3.2...v5.0.0-next.1)
10
12
 
package/CodeExamples.md CHANGED
@@ -78,7 +78,7 @@ Start by importing all of the necessary dependencies
78
78
  ```Typescript
79
79
  import fs from 'fs'
80
80
 
81
- import { ethers, providers, Signer } from 'ethers'
81
+ import { ethers, formatEther, getAddress, JsonRpcProvider, Signer, toBeHex } from 'ethers'
82
82
  import crypto from 'crypto-js'
83
83
  import { homedir } from 'os'
84
84
  import {
@@ -119,7 +119,7 @@ describe('Marketplace flow tests
119
119
  Now we define the variables which we will need later
120
120
 
121
121
  ```Typescript
122
- let provider: ethers.providers.JsonRpcProvider
122
+ let provider: JsonRpcProvider
123
123
  let config: Config
124
124
  let aquarius: Aquarius
125
125
  let datatoken: Datatoken
@@ -197,7 +197,7 @@ Next, we define the metadata that will describe our data asset. This is what we
197
197
  ## 5. Load the configuration, initialize accounts and deploy contracts
198
198
  ```Typescript
199
199
 
200
- provider = new providers.JsonRpcProvider(
200
+ provider = new JsonRpcProvider(
201
201
  process.env.NODE_URI || configHelperNetworks[1].nodeUri
202
202
  )
203
203
  publisherAccount = (await provider.getSigner(0)) as Signer
@@ -252,7 +252,7 @@ you need to mint oceans to mentioned accounts only if you are using barge to tes
252
252
  ]
253
253
 
254
254
  const tokenContract = new ethers.Contract(addresses.Ocean, minAbi, publisherAccount)
255
- const estGasPublisher = await tokenContract.estimateGas.mint(
255
+ const estGasPublisher = await tokenContract.mint.estimateGas(
256
256
  await publisherAccount.getAddress(),
257
257
  amountToUnits(null, null, '1000', 18)
258
258
  )
@@ -290,10 +290,11 @@ you need to mint oceans to mentioned accounts only if you are using barge to tes
290
290
 
291
291
  ### 6.1 Publish a dataset (create NFT + Datatoken) with a fixed rate exchange
292
292
  ```Typescript
293
+ const { chainId } = await publisherAccount.provider.getNetwork()
293
294
  const factory = new NftFactory(
294
295
  addresses.ERC721Factory,
295
296
  publisherAccount,
296
- await publisherAccount.getChainId()
297
+ Number(chainId)
297
298
  )
298
299
 
299
300
  const nftParams: NftCreateData = {
@@ -357,10 +358,8 @@ Now let's console log each of those values to check everything is working
357
358
 
358
359
  ### 6.2 Set metadata in the fixed rate exchange NFT
359
360
  ```Typescript
360
- const nft = new Nft(
361
- publisherAccount,
362
- (await publisherAccount.provider.getNetwork()).chainId
363
- )
361
+ const { chainId } = await publisherAccount.provider.getNetwork()
362
+ const nft = new Nft(publisherAccount, Number(chainId))
364
363
 
365
364
  fixedDDO = { ...genericAsset }
366
365
 
@@ -368,10 +367,9 @@ Now let's console log each of those values to check everything is working
368
367
  Now we are going to update the ddo and set the did
369
368
  ```Typescript
370
369
 
371
- fixedDDO.chainId = (await publisherAccount.provider.getNetwork()).chainId
370
+ fixedDDO.chainId = Number(chainId)
372
371
  fixedDDO.id =
373
- 'did:op:' +
374
- SHA256(ethers.utils.getAddress(freNftAddress) + fixedDDO.chainId.toString(10))
372
+ 'did:op:' + SHA256(getAddress(freNftAddress) + fixedDDO.chainId.toString(10))
375
373
  fixedDDO.nftAddress = freNftAddress
376
374
 
377
375
  ```
@@ -410,7 +408,7 @@ Now let's console log the DID to check everything is working
410
408
  0,
411
409
  providerUrl,
412
410
  '',
413
- ethers.utils.hexlify(2),
411
+ toBeHex(2),
414
412
  encryptedDDO,
415
413
  isAssetValid.hash
416
414
  )
@@ -419,11 +417,8 @@ Now let's console log the DID to check everything is working
419
417
 
420
418
  ### 6.3 Marketplace displays fixed rate asset for sale
421
419
  ```Typescript
422
- const fixedRate = new FixedRateExchange(
423
- freAddress,
424
- publisherAccount,
425
- await publisherAccount.getChainId()
426
- )
420
+ const { chainId } = await publisherAccount.provider.getNetwork()
421
+ const fixedRate = new FixedRateExchange(freAddress, publisherAccount, Number(chainId))
427
422
  const oceanAmount = await (
428
423
  await fixedRate.calcBaseInGivenDatatokensOut(freId, '1')
429
424
  ).baseTokenAmount
@@ -438,7 +433,8 @@ Now that the market has fetched those values it can display the asset on the fro
438
433
 
439
434
  ### 7.1 Consumer buys a fixed rate asset data asset, and downloads it
440
435
  ```Typescript
441
- datatoken = new Datatoken(publisherAccount, await publisherAccount.getChainId())
436
+ const { chainId } = await publisherAccount.provider.getNetwork()
437
+ datatoken = new Datatoken(publisherAccount, Number(chainId))
442
438
  const DATATOKEN_AMOUNT = '10000'
443
439
 
444
440
  await datatoken.mint(
@@ -448,7 +444,7 @@ Now that the market has fetched those values it can display the asset on the fro
448
444
  )
449
445
 
450
446
  const consumerBalance = await provider.getBalance(await consumerAccount.getAddress())
451
- const consumerETHBalance = ethers.utils.formatEther(consumerBalance)
447
+ const consumerETHBalance = formatEther(consumerBalance)
452
448
 
453
449
  ```
454
450
  Let's do a quick check of the consumer ETH balance before the swap
@@ -487,11 +483,7 @@ Before we call the contract we have to call `approve` so that the contract can m
487
483
  DATATOKEN_AMOUNT
488
484
  )
489
485
 
490
- const fixedRate = new FixedRateExchange(
491
- freAddress,
492
- consumerAccount,
493
- await consumerAccount.getChainId()
494
- )
486
+ const fixedRate = new FixedRateExchange(freAddress, consumerAccount, Number(chainId))
495
487
 
496
488
  ```
497
489
  Now we can make the contract call
@@ -548,7 +540,7 @@ Next, we need to initialize the provider
548
540
  providerFees.providerFeeAmount
549
541
  )
550
542
 
551
- datatoken = new Datatoken(consumerAccount, await consumerAccount.getChainId())
543
+ datatoken = new Datatoken(consumerAccount, Number(chainId))
552
544
 
553
545
  ```
554
546
  Lets now make the payment
@@ -609,10 +601,11 @@ Lets check that the download URL was successfully received
609
601
 
610
602
  ### 8.1 Publish a dataset (create NFT + Datatoken) with a dispenser
611
603
  ```Typescript
604
+ const { chainId } = await publisherAccount.provider.getNetwork()
612
605
  const factory = new NftFactory(
613
606
  addresses.ERC721Factory,
614
607
  publisherAccount,
615
- await publisherAccount.getChainId()
608
+ Number(chainId)
616
609
  )
617
610
 
618
611
  const nftParams: NftCreateData = {
@@ -667,19 +660,16 @@ Lets check that we managed to received all of those values without any problems
667
660
  -->
668
661
  ### 8.2 Set metadata in the dispenser NFT
669
662
  ```Typescript
670
- const nft = new Nft(
671
- publisherAccount,
672
- (await publisherAccount.provider.getNetwork()).chainId
673
- )
663
+ const { chainId } = await publisherAccount.provider.getNetwork()
664
+ const nft = new Nft(publisherAccount, Number(chainId))
674
665
 
675
666
  ```
676
667
  Lets start by updating the ddo and setting the did
677
668
  ```Typescript
678
- fixedDDO.chainId = (await publisherAccount.provider.getNetwork()).chainId
669
+ fixedDDO.chainId = Number(chainId)
679
670
 
680
671
  fixedDDO.id =
681
- 'did:op:' +
682
- SHA256(ethers.utils.getAddress(dispenserNftAddress) + fixedDDO.chainId.toString(10))
672
+ 'did:op:' + SHA256(getAddress(dispenserNftAddress) + fixedDDO.chainId.toString(10))
683
673
  fixedDDO.nftAddress = dispenserNftAddress
684
674
  ```
685
675
  Now we need to encrypt file(s) using provider
@@ -712,7 +702,7 @@ Now we need to encrypt file(s) using provider
712
702
  0,
713
703
  providerUrl,
714
704
  '',
715
- ethers.utils.hexlify(2),
705
+ toBeHex(2),
716
706
  encryptedDDO,
717
707
  isAssetValid.hash
718
708
  )
@@ -725,12 +715,9 @@ Now we need to encrypt file(s) using provider
725
715
 
726
716
  ### 9.1 Consumer gets a dispenser data asset, and downloads it
727
717
  ```Typescript
728
- datatoken = new Datatoken(publisherAccount, await publisherAccount.getChainId())
729
- const dispenser = new Dispenser(
730
- addresses.Dispenser,
731
- consumerAccount,
732
- await consumerAccount.getChainId()
733
- )
718
+ const { chainId } = await publisherAccount.provider.getNetwork()
719
+ datatoken = new Datatoken(publisherAccount, Number(chainId))
720
+ const dispenser = new Dispenser(addresses.Dispenser, consumerAccount, Number(chainId))
734
721
 
735
722
  let consumerDTBalance = await balance(
736
723
  consumerAccount,
@@ -759,7 +746,7 @@ Now we need to encrypt file(s) using provider
759
746
  const resolvedDDO = await aquarius.waitForIndexer(fixedDDO.id)
760
747
  assert(resolvedDDO, 'Cannot fetch DDO from Aquarius')
761
748
 
762
- datatoken = new Datatoken(consumerAccount, await consumerAccount.getChainId())
749
+ datatoken = new Datatoken(consumerAccount, Number(chainId))
763
750
 
764
751
  ```
765
752
  At this point we need to encrypt file(s) using provider
@@ -843,7 +830,8 @@ Here are the steps:
843
830
  ### 10.1 Add key-value pair to data NFT
844
831
  Let's start by using the `setData` method to update the nft key value store with some data
845
832
  ```Typescript
846
- const nft = new Nft(publisherAccount, await publisherAccount.getChainId())
833
+ const { chainId } = await publisherAccount.provider.getNetwork()
834
+ const nft = new Nft(publisherAccount, Number(chainId))
847
835
  const data = 'SomeData'
848
836
  try {
849
837
  await nft.setData(
@@ -121,7 +121,7 @@ Start by importing all of the necessary dependencies
121
121
  import fs from 'fs'
122
122
  import { homedir } from 'os'
123
123
 
124
- import { ethers, providers, Signer } from 'ethers'
124
+ import { ethers, getAddress, JsonRpcProvider, parseEther, Signer, toBeHex } from 'ethers'
125
125
  import {
126
126
  ProviderInstance,
127
127
  Aquarius,
@@ -152,6 +152,7 @@ import {
152
152
  import crypto from 'crypto-js'
153
153
  import { DDO } from '@oceanprotocol/ddo-js'
154
154
  import { EscrowContract } from '../../src/contracts/Escrow.js'
155
+ import BigNumber from 'bignumber.js'
155
156
  const { SHA256 } = crypto
156
157
  ```
157
158
 
@@ -307,17 +308,12 @@ async function createAssetHelper(
307
308
  ddo: DDO,
308
309
  providerUrl: string
309
310
  ) {
310
- const nft = new Nft(owner, (await owner.provider.getNetwork()).chainId)
311
+ const { chainId } = await owner.provider.getNetwork()
312
+ const nft = new Nft(owner, Number(chainId))
311
313
 
312
- const nftFactory = new NftFactory(
313
- addresses.ERC721Factory,
314
- owner,
315
- await owner.getChainId()
316
- )
317
-
318
- const chain = (await owner.provider.getNetwork()).chainId
314
+ const nftFactory = new NftFactory(addresses.ERC721Factory, owner, Number(chainId))
319
315
 
320
- ddo.chainId = parseInt(chain.toString(10))
316
+ ddo.chainId = Number(chainId)
321
317
  const nftParamsAsset: NftCreateData = {
322
318
  name,
323
319
  symbol,
@@ -351,14 +347,22 @@ async function createAssetHelper(
351
347
  // create the files encrypted string
352
348
  assetUrl.datatokenAddress = datatokenAddressAsset
353
349
  assetUrl.nftAddress = nftAddress
354
- ddo.services[0].files = await ProviderInstance.encrypt(assetUrl, chain, providerUrl)
350
+ ddo.services[0].files = await ProviderInstance.encrypt(
351
+ assetUrl,
352
+ Number(chainId),
353
+ providerUrl
354
+ )
355
355
  ddo.services[0].datatokenAddress = datatokenAddressAsset
356
356
  ddo.services[0].serviceEndpoint = providerUrl
357
357
 
358
358
  ddo.nftAddress = nftAddress
359
- ddo.id = 'did:op:' + SHA256(ethers.utils.getAddress(nftAddress) + chain.toString(10))
359
+ ddo.id = 'did:op:' + SHA256(ethers.getAddress(nftAddress) + chainId.toString(10))
360
360
 
361
- const encryptedResponse = await ProviderInstance.encrypt(ddo, chain, providerUrl)
361
+ const encryptedResponse = await ProviderInstance.encrypt(
362
+ ddo,
363
+ Number(chainId),
364
+ providerUrl
365
+ )
362
366
  const validateResult = await aquariusInstance.validate(ddo, owner, providerUrl)
363
367
  await nft.setMetadata(
364
368
  nftAddress,
@@ -366,7 +370,7 @@ async function createAssetHelper(
366
370
  0,
367
371
  providerUrl,
368
372
  '',
369
- ethers.utils.hexlify(2),
373
+ toBeHex(2),
370
374
  encryptedResponse,
371
375
  validateResult.hash
372
376
  )
@@ -431,7 +435,7 @@ describe('Compute-to-data example tests
431
435
  We need to load the configuration. Add the following code into your `run(){ }` function
432
436
  ```Typescript
433
437
 
434
- const provider = new providers.JsonRpcProvider(
438
+ const provider = new JsonRpcProvider(
435
439
  process.env.NODE_URI || configHelperNetworks[1].nodeUri
436
440
  )
437
441
  publisherAccount = (await provider.getSigner(0)) as Signer
@@ -490,7 +494,7 @@ you need to mint oceans to mentioned accounts only if you are using barge to tes
490
494
  ]
491
495
 
492
496
  const tokenContract = new ethers.Contract(addresses.Ocean, minAbi, publisherAccount)
493
- const estGasPublisher = await tokenContract.estimateGas.mint(
497
+ const estGasPublisher = await tokenContract.mint.estimateGas(
494
498
  await publisherAccount.getAddress(),
495
499
  amountToUnits(null, null, '1000', 18)
496
500
  )
@@ -575,10 +579,8 @@ Now, let's check that we successfully published a algorithm (create NFT + Datato
575
579
 
576
580
  ### 8.1 Mint dataset and algorithm datatokens to publisher
577
581
  ```Typescript
578
- const datatoken = new Datatoken(
579
- publisherAccount,
580
- (await publisherAccount.provider.getNetwork()).chainId
581
- )
582
+ const { chainId } = await publisherAccount.provider.getNetwork()
583
+ const datatoken = new Datatoken(publisherAccount, Number(chainId))
582
584
  await datatoken.mint(
583
585
  resolvedDatasetDdo.services[0].datatokenAddress,
584
586
  await publisherAccount.getAddress(),
@@ -612,10 +614,8 @@ Now, let's check that we successfully published a algorithm (create NFT + Datato
612
614
 
613
615
  ### 10.1 Start a compute job using a free C2D environment
614
616
  <!--
615
- datatoken = new Datatoken(
616
- consumerAccount,
617
- (await consumerAccount.provider.getNetwork()).chainId
618
- )
617
+ const { chainId } = await consumerAccount.provider.getNetwork()
618
+ datatoken = new Datatoken(consumerAccount, Number(chainId))
619
619
  -->
620
620
 
621
621
  let's check the free compute environment
@@ -754,10 +754,8 @@ let's check the free compute environment
754
754
 
755
755
  ### 12.1 Start a compute job using a paid C2D resources
756
756
  <!--
757
- datatoken = new Datatoken(
758
- consumerAccount,
759
- (await consumerAccount.provider.getNetwork()).chainId
760
- )
757
+ const { chainId } = await consumerAccount.provider.getNetwork()
758
+ datatoken = new Datatoken(consumerAccount, Number(chainId))
761
759
  -->
762
760
 
763
761
  let's select compute environment which have free and paid resources
@@ -826,9 +824,7 @@ let's select compute environment which have free and paid resources
826
824
  providerUrl,
827
825
  consumerAccount,
828
826
  resources,
829
- (
830
- await consumerAccount.provider.getNetwork()
831
- ).chainId
827
+ Number(chainId)
832
828
  )
833
829
 
834
830
  console.log(
@@ -845,7 +841,7 @@ let's select compute environment which have free and paid resources
845
841
  Let's check funds for escrow payment
846
842
  ```Typescript
847
843
  const escrow = new EscrowContract(
848
- ethers.utils.getAddress(providerInitializeComputeResults.payment.escrowAddress),
844
+ getAddress(providerInitializeComputeResults.payment.escrowAddress),
849
845
  consumerAccount
850
846
  )
851
847
  const paymentTokenPublisher = new Datatoken(publisherAccount)
@@ -854,18 +850,18 @@ let's select compute environment which have free and paid resources
854
850
  await publisherAccount.getAddress()
855
851
  )
856
852
  assert(
857
- ethers.utils.parseEther(balancePublisherPaymentToken) > ethers.BigNumber.from(0),
853
+ new BigNumber(parseEther(balancePublisherPaymentToken)).isGreaterThan(0),
858
854
  'Balance should be higher than 0'
859
855
  )
860
856
  const tx = await publisherAccount.sendTransaction({
861
857
  to: computeEnv.consumerAddress,
862
- value: ethers.utils.parseEther('1.5')
858
+ value: parseEther('1.5')
863
859
  })
864
860
  await tx.wait()
865
861
 
866
862
  await paymentTokenPublisher.transfer(
867
863
  paymentToken,
868
- ethers.utils.getAddress(computeEnv.consumerAddress),
864
+ getAddress(computeEnv.consumerAddress),
869
865
  (Number(balancePublisherPaymentToken) / 2).toString()
870
866
  )
871
867
  const amountToDeposit = (
@@ -913,9 +909,7 @@ let's select compute environment which have free and paid resources
913
909
  computeValidUntil,
914
910
  paymentToken,
915
911
  resources,
916
- (
917
- await consumerAccount.provider.getNetwork()
918
- ).chainId
912
+ Number(chainId)
919
913
  )
920
914
  ```
921
915