@oceanprotocol/lib 1.1.8 → 2.0.0-next.0
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 +28 -16
- package/CodeExamples.md +28 -315
- package/README.md +4 -7
- package/dist/lib.js +1 -1
- package/dist/lib.js.map +1 -1
- package/dist/lib.modern.js +1 -1
- package/dist/lib.modern.js.map +1 -1
- package/dist/lib.module.js +1 -1
- package/dist/lib.module.js.map +1 -1
- package/dist/lib.umd.js +1 -1
- package/dist/lib.umd.js.map +1 -1
- package/dist/src/@types/Asset.d.ts +4 -4
- package/dist/src/@types/Compute.d.ts +1 -1
- package/dist/src/@types/DDO/DDO.d.ts +2 -5
- package/dist/src/@types/{Erc20.d.ts → Datatoken.d.ts} +18 -1
- package/dist/src/@types/Dispenser.d.ts +9 -0
- package/dist/src/@types/FixedPrice.d.ts +24 -0
- package/dist/src/@types/{Erc721.d.ts → NFT.d.ts} +6 -0
- package/dist/src/@types/NFTFactory.d.ts +20 -0
- package/dist/src/@types/Provider.d.ts +8 -0
- package/dist/src/@types/ReturnTypes.d.ts +2 -0
- package/dist/src/@types/Router.d.ts +1 -1
- package/dist/src/@types/index.d.ts +11 -8
- package/dist/src/{models → config}/Config.d.ts +2 -23
- package/dist/src/{utils → config}/ConfigHelper.d.ts +1 -1
- package/dist/src/config/index.d.ts +2 -0
- package/dist/src/contracts/Datatoken.d.ts +232 -0
- package/dist/src/contracts/Dispenser.d.ts +73 -0
- package/dist/src/contracts/FixedRateExchange.d.ts +212 -0
- package/dist/src/contracts/NFT.d.ts +197 -0
- package/dist/src/contracts/NFTFactory.d.ts +144 -0
- package/dist/src/contracts/Router.d.ts +92 -0
- package/dist/src/contracts/SmartContract.d.ts +22 -0
- package/dist/src/contracts/SmartContractWithAddress.d.ts +18 -0
- package/dist/src/contracts/index.d.ts +8 -0
- package/dist/src/index.d.ts +4 -7
- package/dist/src/{aquarius → services}/Aquarius.d.ts +2 -3
- package/dist/src/{provider → services}/Provider.d.ts +5 -13
- package/dist/src/services/index.d.ts +2 -0
- package/dist/src/utils/Constants.d.ts +2 -0
- package/dist/src/utils/ContractUtils.d.ts +14 -8
- package/dist/src/utils/DdoHelpers.d.ts +1 -1
- package/dist/src/utils/FetchHelper.d.ts +1 -4
- package/dist/src/utils/Logger.d.ts +0 -1
- package/dist/src/utils/TokenUtils.d.ts +17 -39
- package/dist/src/utils/index.d.ts +6 -7
- package/dist/test/TestContractHandler.d.ts +4 -4
- package/dist/test/config.d.ts +1 -1
- package/dist/test/unit/{tokens/Datatoken.test.d.ts → Datatoken.test.d.ts} +0 -0
- package/dist/test/unit/{pools/dispenser/Dispenser.test.d.ts → Dispenser.test.d.ts} +0 -0
- package/dist/test/unit/{pools/fixedRate/FixedRateExchange.test.d.ts → FixedRateExchange.test.d.ts} +0 -0
- package/dist/test/unit/{tokens/Nft.test.d.ts → Nft.test.d.ts} +0 -0
- package/dist/test/unit/{factories/NftFactory.test.d.ts → NftFactory.test.d.ts} +0 -0
- package/dist/test/unit/{pools/Router.test.d.ts → Router.test.d.ts} +0 -0
- package/package.json +5 -18
- package/dist/src/@types/Pool.d.ts +0 -45
- package/dist/src/aquarius/index.d.ts +0 -1
- package/dist/src/factories/NFTFactory.d.ts +0 -275
- package/dist/src/factories/index.d.ts +0 -1
- package/dist/src/models/index.d.ts +0 -1
- package/dist/src/pools/Router.d.ts +0 -228
- package/dist/src/pools/balancer/Pool.d.ts +0 -395
- package/dist/src/pools/balancer/index.d.ts +0 -1
- package/dist/src/pools/dispenser/Dispenser.d.ts +0 -145
- package/dist/src/pools/dispenser/index.d.ts +0 -1
- package/dist/src/pools/fixedRate/FixedRateExchange.d.ts +0 -388
- package/dist/src/pools/fixedRate/index.d.ts +0 -1
- package/dist/src/pools/index.d.ts +0 -5
- package/dist/src/pools/ssContracts/SideStaking.d.ts +0 -133
- package/dist/src/pools/ssContracts/index.d.ts +0 -1
- package/dist/src/provider/index.d.ts +0 -1
- package/dist/src/tokens/Datatoken.d.ts +0 -413
- package/dist/src/tokens/NFT.d.ts +0 -364
- package/dist/src/tokens/index.d.ts +0 -2
- package/dist/src/utils/ConversionTypeHelper.d.ts +0 -3
- package/dist/src/utils/PoolHelpers.d.ts +0 -8
- package/dist/test/unit/pools/balancer/Pool.test.d.ts +0 -1
- package/dist/test/unit/pools/ssContracts/SideStaking.test.d.ts +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -4,10 +4,34 @@ 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
|
+
#### [v2.0.0-next.0](https://github.com/oceanprotocol/ocean.js/compare/v1.1.8...v2.0.0-next.0)
|
|
8
|
+
|
|
9
|
+
- Eip 1559 support [`#1579`](https://github.com/oceanprotocol/ocean.js/pull/1579)
|
|
10
|
+
- add gas fee multiplier to max priority fee [`#1581`](https://github.com/oceanprotocol/ocean.js/pull/1581)
|
|
11
|
+
- Remove amm pools [`#1568`](https://github.com/oceanprotocol/ocean.js/pull/1568)
|
|
12
|
+
- Fix c2d integration test [`#1567`](https://github.com/oceanprotocol/ocean.js/pull/1567)
|
|
13
|
+
- Issue-#1474: Refactoring(11): Review try catch clauses [`#1524`](https://github.com/oceanprotocol/ocean.js/pull/1524)
|
|
14
|
+
- Issue-#1474: Refactoring (10): General renaming [`#1565`](https://github.com/oceanprotocol/ocean.js/pull/1565)
|
|
15
|
+
- Issue-#1474: Refactoring (9): Refactor estimategas. Change from function to parameter in real functions [`#1509`](https://github.com/oceanprotocol/ocean.js/pull/1509)
|
|
16
|
+
- Issue-#1474: Refactoring (8): Rename from erc20 to datatoken [`#1507`](https://github.com/oceanprotocol/ocean.js/pull/1507)
|
|
17
|
+
- Issue-#1474: Refactoring (7): Rename from erc721 to nft [`#1506`](https://github.com/oceanprotocol/ocean.js/pull/1506)
|
|
18
|
+
- Issue-#1474: Refactoring(6). Refactor estimate gas function names [`#1505`](https://github.com/oceanprotocol/ocean.js/pull/1505)
|
|
19
|
+
- Issue-#1474: Refactoring(5). Move functions from \utils to classes [`#1504`](https://github.com/oceanprotocol/ocean.js/pull/1504)
|
|
20
|
+
- Issue-#1474: Refactoring(4). Create class inheritance [`#1501`](https://github.com/oceanprotocol/ocean.js/pull/1501)
|
|
21
|
+
- Issue-#1474: Refactoring(3). Move types to src\@types folder [`#1500`](https://github.com/oceanprotocol/ocean.js/pull/1500)
|
|
22
|
+
- Issue-#1474: Refactoring (2). Restructure imports [`#1493`](https://github.com/oceanprotocol/ocean.js/pull/1493)
|
|
23
|
+
- Issue-#1474: Refactoring (1). Restructure file location [`#1492`](https://github.com/oceanprotocol/ocean.js/pull/1492)
|
|
24
|
+
- updating packages [`77eaccd`](https://github.com/oceanprotocol/ocean.js/commit/77eaccdbed9f962f90b24c21945ec1767c7542ce)
|
|
25
|
+
- add suport for eip 1559 [`60a3f5a`](https://github.com/oceanprotocol/ocean.js/commit/60a3f5af2033e55e5a8d97e4abdb749899b542b4)
|
|
26
|
+
- Updating release-it [`8a6f009`](https://github.com/oceanprotocol/ocean.js/commit/8a6f00929070b60e13c2ed89e14092d50a1e33fd)
|
|
27
|
+
|
|
7
28
|
#### [v1.1.8](https://github.com/oceanprotocol/ocean.js/compare/v1.1.7...v1.1.8)
|
|
8
29
|
|
|
30
|
+
> 9 August 2022
|
|
31
|
+
|
|
9
32
|
- Let do any query in Aquarius [`#1576`](https://github.com/oceanprotocol/ocean.js/pull/1576)
|
|
10
33
|
- let do any query in Aquarius [`02b805a`](https://github.com/oceanprotocol/ocean.js/commit/02b805a45ddbc77a0d4675a06e73b31d0494d55f)
|
|
34
|
+
- Release 1.1.8 [`0f0030d`](https://github.com/oceanprotocol/ocean.js/commit/0f0030daf34cc0a4c24647b0f93570312e4eac97)
|
|
11
35
|
|
|
12
36
|
#### [v1.1.7](https://github.com/oceanprotocol/ocean.js/compare/v1.1.6...v1.1.7)
|
|
13
37
|
|
|
@@ -80,21 +104,7 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
|
|
|
80
104
|
- Bump typedoc from 0.22.15 to 0.22.17 [`#1514`](https://github.com/oceanprotocol/ocean.js/pull/1514)
|
|
81
105
|
- Release 1.1.3 [`7772e93`](https://github.com/oceanprotocol/ocean.js/commit/7772e9387ef9d63f98ea80cfd4eefbea963dd0ad)
|
|
82
106
|
|
|
83
|
-
#### [v1.1.2](https://github.com/oceanprotocol/ocean.js/compare/v1.
|
|
84
|
-
|
|
85
|
-
> 15 June 2022
|
|
86
|
-
|
|
87
|
-
- Release 1.1.2 [`85bf271`](https://github.com/oceanprotocol/ocean.js/commit/85bf2716e26d8691aeb9d5504e563d557419dc2e)
|
|
88
|
-
- manual bump fix [`5674a54`](https://github.com/oceanprotocol/ocean.js/commit/5674a547d1d367ce88b3595f0be8ebbf12274266)
|
|
89
|
-
|
|
90
|
-
#### [v1.1.1](https://github.com/oceanprotocol/ocean.js/compare/v1.1.0...v1.1.1)
|
|
91
|
-
|
|
92
|
-
> 15 June 2022
|
|
93
|
-
|
|
94
|
-
- Release 1.1.1 [`ea48e01`](https://github.com/oceanprotocol/ocean.js/commit/ea48e015ac8299f71d57a929f8f30c5d1a8446e7)
|
|
95
|
-
- manual bump fix [`a362410`](https://github.com/oceanprotocol/ocean.js/commit/a36241004b1d9578ec5c02d9d6e64d9750c53a7b)
|
|
96
|
-
|
|
97
|
-
#### [v1.1.0](https://github.com/oceanprotocol/ocean.js/compare/v1.0.0...v1.1.0)
|
|
107
|
+
#### [v1.1.2](https://github.com/oceanprotocol/ocean.js/compare/v1.0.0...v1.1.2)
|
|
98
108
|
|
|
99
109
|
> 15 June 2022
|
|
100
110
|
|
|
@@ -102,7 +112,9 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
|
|
|
102
112
|
- Bump @types/node from 17.0.35 to 17.0.44 [`#1513`](https://github.com/oceanprotocol/ocean.js/pull/1513)
|
|
103
113
|
- Bump eslint-config-oceanprotocol from 1.5.0 to 2.0.1 [`#1466`](https://github.com/oceanprotocol/ocean.js/pull/1466)
|
|
104
114
|
- update to new schema & compute fixes [`#1510`](https://github.com/oceanprotocol/ocean.js/pull/1510)
|
|
105
|
-
- Release 1.1.
|
|
115
|
+
- Release 1.1.2 [`85bf271`](https://github.com/oceanprotocol/ocean.js/commit/85bf2716e26d8691aeb9d5504e563d557419dc2e)
|
|
116
|
+
- manual bump fix [`5674a54`](https://github.com/oceanprotocol/ocean.js/commit/5674a547d1d367ce88b3595f0be8ebbf12274266)
|
|
117
|
+
- manual bump fix [`a362410`](https://github.com/oceanprotocol/ocean.js/commit/a36241004b1d9578ec5c02d9d6e64d9750c53a7b)
|
|
106
118
|
|
|
107
119
|
#### [v1.0.0](https://github.com/oceanprotocol/ocean.js/compare/v1.0.0-next.45...v1.0.0)
|
|
108
120
|
|
package/CodeExamples.md
CHANGED
|
@@ -23,9 +23,8 @@ Here are the steps:
|
|
|
23
23
|
3. [Install dependencies](#-install-dependencies)
|
|
24
24
|
4. [Initialize accounts and deploy contracts](#-initialize-accounts-and-deploy-contracts)
|
|
25
25
|
5. [Import dependencies and add variables and constants](#-import-dependencies-and-add-variables-and-constants)
|
|
26
|
-
6. [Publish Data NFT and a Datatoken with a
|
|
27
|
-
7. [Publish Data NFT and a Datatoken with a
|
|
28
|
-
8. [Publish Data NFT and a Datatoken with a dispenser](#-publish-data-nft-and-a-datatoken-with-a-dispenser)
|
|
26
|
+
6. [Publish Data NFT and a Datatoken with a fixed rate exchange](#-publish-data-nft-and-a-datatoken-with-a-fixed-rate-exchange)
|
|
27
|
+
7. [Publish Data NFT and a Datatoken with a dispenser](#-publish-data-nft-and-a-datatoken-with-a-dispenser)
|
|
29
28
|
|
|
30
29
|
## 0. Prerequisites
|
|
31
30
|
Before we start it is important that you have all of the necessary prerequisites installed on your computer.
|
|
@@ -88,7 +87,6 @@ Start by importing all of the necessary dependencies
|
|
|
88
87
|
|
|
89
88
|
import { SHA256 } from 'crypto-js'
|
|
90
89
|
import {
|
|
91
|
-
AmountsOutMaxFee,
|
|
92
90
|
approve,
|
|
93
91
|
Aquarius,
|
|
94
92
|
balance,
|
|
@@ -97,7 +95,7 @@ import {
|
|
|
97
95
|
Dispenser,
|
|
98
96
|
DispenserCreationParams,
|
|
99
97
|
downloadFile,
|
|
100
|
-
|
|
98
|
+
DatatokenCreateParams,
|
|
101
99
|
Files,
|
|
102
100
|
FixedRateExchange,
|
|
103
101
|
FreCreationParams,
|
|
@@ -105,11 +103,8 @@ import {
|
|
|
105
103
|
Nft,
|
|
106
104
|
NftCreateData,
|
|
107
105
|
NftFactory,
|
|
108
|
-
Pool,
|
|
109
|
-
PoolCreationParams,
|
|
110
106
|
ProviderFees,
|
|
111
107
|
ProviderInstance,
|
|
112
|
-
TokenInOutMarket,
|
|
113
108
|
transfer,
|
|
114
109
|
ZERO_ADDRESS
|
|
115
110
|
} from '../../src'
|
|
@@ -130,9 +125,6 @@ Now we define the variables which we will need later
|
|
|
130
125
|
let consumerAccount: string
|
|
131
126
|
let stakerAccount: string
|
|
132
127
|
let addresses: any
|
|
133
|
-
let poolNftAddress: string
|
|
134
|
-
let poolDatatokenAddress: string
|
|
135
|
-
let poolAddress: string
|
|
136
128
|
let freNftAddress: string
|
|
137
129
|
let freDatatokenAddress: string
|
|
138
130
|
let freAddress: string
|
|
@@ -144,8 +136,6 @@ Now we define the variables which we will need later
|
|
|
144
136
|
|
|
145
137
|
We also define some constants that we will use:
|
|
146
138
|
```Typescript
|
|
147
|
-
const POOL_NFT_NAME = 'Datatoken 1'
|
|
148
|
-
const POOL_NFT_SYMBOL = 'DT1'
|
|
149
139
|
const FRE_NFT_NAME = 'Datatoken 2'
|
|
150
140
|
const FRE_NFT_SYMBOL = 'DT2'
|
|
151
141
|
const DISP_NFT_NAME = 'Datatoken 3'
|
|
@@ -235,292 +225,14 @@ Again, lets console log the values so that we can check that they have been save
|
|
|
235
225
|
|
|
236
226
|
### 5.3 We send some OCEAN to consumer and staker accounts
|
|
237
227
|
```Typescript
|
|
238
|
-
transfer(web3, publisherAccount, addresses.Ocean, consumerAccount, '100')
|
|
239
|
-
transfer(web3, publisherAccount, addresses.Ocean, stakerAccount, '100')
|
|
228
|
+
transfer(web3, config, publisherAccount, addresses.Ocean, consumerAccount, '100')
|
|
229
|
+
transfer(web3, config, publisherAccount, addresses.Ocean, stakerAccount, '100')
|
|
240
230
|
|
|
241
231
|
```
|
|
242
232
|
|
|
243
|
-
## 6. Publish Data NFT and a Datatoken with a
|
|
233
|
+
## 6. Publish Data NFT and a Datatoken with a fixed rate exchange
|
|
244
234
|
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
### 6.1 Publish a dataset (create NFT + Datatoken) with a liquidity pool
|
|
248
|
-
```Typescript
|
|
249
|
-
const factory = new NftFactory(addresses.ERC721Factory, web3)
|
|
250
|
-
|
|
251
|
-
const nftParams: NftCreateData = {
|
|
252
|
-
name: POOL_NFT_NAME,
|
|
253
|
-
symbol: POOL_NFT_SYMBOL,
|
|
254
|
-
templateIndex: 1,
|
|
255
|
-
tokenURI: '',
|
|
256
|
-
transferable: true,
|
|
257
|
-
owner: publisherAccount
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
const erc20Params: Erc20CreateParams = {
|
|
261
|
-
templateIndex: 1,
|
|
262
|
-
cap: '100000',
|
|
263
|
-
feeAmount: '0',
|
|
264
|
-
paymentCollector: ZERO_ADDRESS,
|
|
265
|
-
feeToken: ZERO_ADDRESS,
|
|
266
|
-
minter: publisherAccount,
|
|
267
|
-
mpFeeAddress: ZERO_ADDRESS
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
const poolParams: PoolCreationParams = {
|
|
271
|
-
ssContract: addresses.Staking,
|
|
272
|
-
baseTokenAddress: addresses.Ocean,
|
|
273
|
-
baseTokenSender: addresses.ERC721Factory,
|
|
274
|
-
publisherAddress: publisherAccount,
|
|
275
|
-
marketFeeCollector: publisherAccount,
|
|
276
|
-
poolTemplateAddress: addresses.poolTemplate,
|
|
277
|
-
rate: '1',
|
|
278
|
-
baseTokenDecimals: 18,
|
|
279
|
-
vestingAmount: '10000',
|
|
280
|
-
vestedBlocks: 2500000,
|
|
281
|
-
initialBaseTokenLiquidity: '2000',
|
|
282
|
-
swapFeeLiquidityProvider: '0.001',
|
|
283
|
-
swapFeeMarketRunner: '0.001'
|
|
284
|
-
}
|
|
285
|
-
```
|
|
286
|
-
Before we call the contract we have to call `approve` so that the contract can move our tokens. This is standard when using any ERC20 tokens
|
|
287
|
-
```Typescript
|
|
288
|
-
await approve(
|
|
289
|
-
web3,
|
|
290
|
-
publisherAccount,
|
|
291
|
-
addresses.Ocean,
|
|
292
|
-
addresses.ERC721Factory,
|
|
293
|
-
poolParams.vestingAmount
|
|
294
|
-
)
|
|
295
|
-
|
|
296
|
-
```
|
|
297
|
-
Now we can make the contract call
|
|
298
|
-
```Typescript
|
|
299
|
-
const tx = await factory.createNftErc20WithPool(
|
|
300
|
-
publisherAccount,
|
|
301
|
-
nftParams,
|
|
302
|
-
erc20Params,
|
|
303
|
-
poolParams
|
|
304
|
-
)
|
|
305
|
-
|
|
306
|
-
poolNftAddress = tx.events.NFTCreated.returnValues[0]
|
|
307
|
-
poolDatatokenAddress = tx.events.TokenCreated.returnValues[0]
|
|
308
|
-
poolAddress = tx.events.NewPool.returnValues[0]
|
|
309
|
-
```
|
|
310
|
-
Now, we did quite a few things there. Let's check that we successfully published a dataset (create NFT + Datatoken) with a liquidity pool
|
|
311
|
-
```Typescript
|
|
312
|
-
console.log(`Pool NFT address: ${poolNftAddress}`)
|
|
313
|
-
console.log(`Pool Datatoken address: ${poolDatatokenAddress}`)
|
|
314
|
-
console.log(`Pool address: ${poolAddress}`)
|
|
315
|
-
|
|
316
|
-
```
|
|
317
|
-
|
|
318
|
-
### 6.2 Set metadata in the pool NFT
|
|
319
|
-
```Typescript
|
|
320
|
-
const nft = new Nft(web3)
|
|
321
|
-
```
|
|
322
|
-
Now we update the ddo and set the right did
|
|
323
|
-
```Typescript
|
|
324
|
-
DDO.chainId = await web3.eth.getChainId()
|
|
325
|
-
DDO.id =
|
|
326
|
-
'did:op:' +
|
|
327
|
-
SHA256(web3.utils.toChecksumAddress(poolNftAddress) + DDO.chainId.toString(10))
|
|
328
|
-
DDO.nftAddress = poolNftAddress
|
|
329
|
-
```
|
|
330
|
-
Next we encrypt the file or files using Ocean Provider. The provider is an off chain proxy built specifically for this task
|
|
331
|
-
```Typescript
|
|
332
|
-
ASSET_URL.datatokenAddress = poolDatatokenAddress
|
|
333
|
-
ASSET_URL.nftAddress = poolNftAddress
|
|
334
|
-
const encryptedFiles = await ProviderInstance.encrypt(ASSET_URL, providerUrl)
|
|
335
|
-
DDO.services[0].files = await encryptedFiles
|
|
336
|
-
DDO.services[0].datatokenAddress = poolDatatokenAddress
|
|
337
|
-
```
|
|
338
|
-
Now let's console log the result to check everything is working
|
|
339
|
-
```Typescript
|
|
340
|
-
console.log(`DID: ${DDO.id}`)
|
|
341
|
-
|
|
342
|
-
const providerResponse = await ProviderInstance.encrypt(DDO, providerUrl)
|
|
343
|
-
const encryptedDDO = await providerResponse
|
|
344
|
-
const metadataHash = getHash(JSON.stringify(DDO))
|
|
345
|
-
await nft.setMetadata(
|
|
346
|
-
poolNftAddress,
|
|
347
|
-
publisherAccount,
|
|
348
|
-
0,
|
|
349
|
-
providerUrl,
|
|
350
|
-
'',
|
|
351
|
-
'0x2',
|
|
352
|
-
encryptedDDO,
|
|
353
|
-
'0x' + metadataHash
|
|
354
|
-
)
|
|
355
|
-
|
|
356
|
-
```
|
|
357
|
-
|
|
358
|
-
### 6.3 User should add liquidity to the pool, receiving LP tokens
|
|
359
|
-
```Typescript
|
|
360
|
-
const pool = new Pool(web3)
|
|
361
|
-
|
|
362
|
-
```
|
|
363
|
-
Before we call the contract we have to call `approve` so that the contract can move our tokens. This is standard when using any ERC20 tokens
|
|
364
|
-
```Typescript
|
|
365
|
-
await approve(web3, stakerAccount, addresses.Ocean, poolAddress, '5', true)
|
|
366
|
-
|
|
367
|
-
```
|
|
368
|
-
Now we can make the contract call
|
|
369
|
-
```Typescript
|
|
370
|
-
await pool.joinswapExternAmountIn(stakerAccount, poolAddress, '5', '0.1')
|
|
371
|
-
|
|
372
|
-
```
|
|
373
|
-
|
|
374
|
-
### 6.4 Marketplace displays pool asset for sale
|
|
375
|
-
```Typescript
|
|
376
|
-
const pool = new Pool(web3)
|
|
377
|
-
const prices = await pool.getAmountInExactOut(
|
|
378
|
-
poolAddress,
|
|
379
|
-
poolDatatokenAddress,
|
|
380
|
-
addresses.Ocean,
|
|
381
|
-
'1',
|
|
382
|
-
'0.01'
|
|
383
|
-
)
|
|
384
|
-
```
|
|
385
|
-
Now let's console log the result to check everything is working
|
|
386
|
-
```Typescript
|
|
387
|
-
console.log(`Price of 1 ${POOL_NFT_SYMBOL} is ${prices.tokenAmount} OCEAN`)
|
|
388
|
-
|
|
389
|
-
```
|
|
390
|
-
|
|
391
|
-
### 6.5 Consumer buys a pool data asset, and downloads it
|
|
392
|
-
```Typescript
|
|
393
|
-
const datatoken = new Datatoken(web3)
|
|
394
|
-
|
|
395
|
-
const consumerETHBalance = await web3.eth.getBalance(consumerAccount)
|
|
396
|
-
```
|
|
397
|
-
Now let's console log the result to check everything is working
|
|
398
|
-
```Typescript
|
|
399
|
-
console.log(`Consumer ETH balance: ${consumerETHBalance}`)
|
|
400
|
-
let consumerOCEANBalance = await balance(web3, addresses.Ocean, consumerAccount)
|
|
401
|
-
```
|
|
402
|
-
Now let's console log consumerOCEANBalance to check everything is working
|
|
403
|
-
```Typescript
|
|
404
|
-
console.log(`Consumer OCEAN balance before swap: ${consumerOCEANBalance}`)
|
|
405
|
-
let consumerDTBalance = await balance(web3, poolDatatokenAddress, consumerAccount)
|
|
406
|
-
```
|
|
407
|
-
Now let's console log POOL_NFT_SYMBOL and consumerDTBalance to check everything is working
|
|
408
|
-
```Typescript
|
|
409
|
-
console.log(`Consumer ${POOL_NFT_SYMBOL} balance before swap: ${consumerDTBalance}`)
|
|
410
|
-
|
|
411
|
-
```
|
|
412
|
-
Before we call the contract we have to call `approve` so that the contract can move our tokens. This is standard when using any ERC20 tokens
|
|
413
|
-
```Typescript
|
|
414
|
-
await approve(web3, consumerAccount, addresses.Ocean, poolAddress, '100')
|
|
415
|
-
|
|
416
|
-
const pool = new Pool(web3)
|
|
417
|
-
const tokenInOutMarket: TokenInOutMarket = {
|
|
418
|
-
tokenIn: addresses.Ocean,
|
|
419
|
-
tokenOut: poolDatatokenAddress,
|
|
420
|
-
marketFeeAddress: consumerAccount
|
|
421
|
-
}
|
|
422
|
-
const amountsInOutMaxFee: AmountsOutMaxFee = {
|
|
423
|
-
maxAmountIn: '10',
|
|
424
|
-
tokenAmountOut: '1',
|
|
425
|
-
swapMarketFee: '0.1'
|
|
426
|
-
}
|
|
427
|
-
|
|
428
|
-
```
|
|
429
|
-
Now we can make the contract call
|
|
430
|
-
```Typescript
|
|
431
|
-
await pool.swapExactAmountOut(
|
|
432
|
-
consumerAccount,
|
|
433
|
-
poolAddress,
|
|
434
|
-
tokenInOutMarket,
|
|
435
|
-
amountsInOutMaxFee
|
|
436
|
-
)
|
|
437
|
-
|
|
438
|
-
consumerOCEANBalance = await balance(web3, addresses.Ocean, consumerAccount)
|
|
439
|
-
```
|
|
440
|
-
Now let's console log the Consumer OCEAN balance after swap to check everything is working
|
|
441
|
-
```Typescript
|
|
442
|
-
console.log(`Consumer OCEAN balance after swap: ${consumerOCEANBalance}`)
|
|
443
|
-
consumerDTBalance = await balance(web3, poolDatatokenAddress, consumerAccount)
|
|
444
|
-
```
|
|
445
|
-
Next let's console log the POOL_NFT_SYMBOL and consumerDTBalance
|
|
446
|
-
```Typescript
|
|
447
|
-
console.log(`Consumer ${POOL_NFT_SYMBOL} balance after swap: ${consumerDTBalance}`)
|
|
448
|
-
|
|
449
|
-
const resolvedDDO = await aquarius.waitForAqua(DDO.id)
|
|
450
|
-
assert(resolvedDDO, 'Cannot fetch DDO from Aquarius')
|
|
451
|
-
|
|
452
|
-
```
|
|
453
|
-
The next step is to initialize the provider instance
|
|
454
|
-
```Typescript
|
|
455
|
-
const initializeData = await ProviderInstance.initialize(
|
|
456
|
-
resolvedDDO.id,
|
|
457
|
-
resolvedDDO.services[0].id,
|
|
458
|
-
0,
|
|
459
|
-
consumerAccount,
|
|
460
|
-
providerUrl
|
|
461
|
-
)
|
|
462
|
-
|
|
463
|
-
const providerFees: ProviderFees = {
|
|
464
|
-
providerFeeAddress: initializeData.providerFee.providerFeeAddress,
|
|
465
|
-
providerFeeToken: initializeData.providerFee.providerFeeToken,
|
|
466
|
-
providerFeeAmount: initializeData.providerFee.providerFeeAmount,
|
|
467
|
-
v: initializeData.providerFee.v,
|
|
468
|
-
r: initializeData.providerFee.r,
|
|
469
|
-
s: initializeData.providerFee.s,
|
|
470
|
-
providerData: initializeData.providerFee.providerData,
|
|
471
|
-
validUntil: initializeData.providerFee.validUntil
|
|
472
|
-
}
|
|
473
|
-
|
|
474
|
-
```
|
|
475
|
-
Now let's make a payment
|
|
476
|
-
```Typescript
|
|
477
|
-
const tx = await datatoken.startOrder(
|
|
478
|
-
poolDatatokenAddress,
|
|
479
|
-
consumerAccount,
|
|
480
|
-
consumerAccount,
|
|
481
|
-
0,
|
|
482
|
-
providerFees
|
|
483
|
-
)
|
|
484
|
-
|
|
485
|
-
```
|
|
486
|
-
Next up, let's get the URL
|
|
487
|
-
```Typescript
|
|
488
|
-
const downloadURL = await ProviderInstance.getDownloadUrl(
|
|
489
|
-
DDO.id,
|
|
490
|
-
consumerAccount,
|
|
491
|
-
DDO.services[0].id,
|
|
492
|
-
0,
|
|
493
|
-
tx.transactionHash,
|
|
494
|
-
providerUrl,
|
|
495
|
-
web3
|
|
496
|
-
)
|
|
497
|
-
|
|
498
|
-
```
|
|
499
|
-
Now let's console log the Download URL to check everything is working
|
|
500
|
-
```Typescript
|
|
501
|
-
console.log(`Download URL: ${downloadURL}`)
|
|
502
|
-
|
|
503
|
-
consumerOCEANBalance = await balance(web3, addresses.Ocean, consumerAccount)
|
|
504
|
-
console.log(`Consumer OCEAN balance after order: ${consumerOCEANBalance}`)
|
|
505
|
-
consumerDTBalance = await balance(web3, poolDatatokenAddress, consumerAccount)
|
|
506
|
-
|
|
507
|
-
```
|
|
508
|
-
Now let's console log the Consumer balance after order to check everything is working
|
|
509
|
-
```Typescript
|
|
510
|
-
console.log(`Consumer ${POOL_NFT_SYMBOL} balance after order: ${consumerDTBalance}`)
|
|
511
|
-
|
|
512
|
-
try {
|
|
513
|
-
const fileData = await downloadFile(downloadURL)
|
|
514
|
-
console.log(fileData)
|
|
515
|
-
} catch (e) {
|
|
516
|
-
assert.fail('Download failed')
|
|
517
|
-
}
|
|
518
|
-
|
|
519
|
-
```
|
|
520
|
-
|
|
521
|
-
## 7. Publish Data NFT and a Datatoken with a fixed rate exchange
|
|
522
|
-
|
|
523
|
-
### 7.1 Publish a dataset (create NFT + Datatoken) with a fixed rate exchange
|
|
235
|
+
### 6.1 Publish a dataset (create NFT + Datatoken) with a fixed rate exchange
|
|
524
236
|
```Typescript
|
|
525
237
|
const factory = new NftFactory(addresses.ERC721Factory, web3)
|
|
526
238
|
|
|
@@ -533,7 +245,7 @@ Now let's console log the Consumer balance after order to check everything is wo
|
|
|
533
245
|
owner: publisherAccount
|
|
534
246
|
}
|
|
535
247
|
|
|
536
|
-
const
|
|
248
|
+
const datatokenParams: DatatokenCreateParams = {
|
|
537
249
|
templateIndex: 1,
|
|
538
250
|
cap: '100000',
|
|
539
251
|
feeAmount: '0',
|
|
@@ -556,10 +268,10 @@ Now let's console log the Consumer balance after order to check everything is wo
|
|
|
556
268
|
withMint: false
|
|
557
269
|
}
|
|
558
270
|
|
|
559
|
-
const tx = await factory.
|
|
271
|
+
const tx = await factory.createNftWithDatatokenWithFixedRate(
|
|
560
272
|
publisherAccount,
|
|
561
273
|
nftParams,
|
|
562
|
-
|
|
274
|
+
datatokenParams,
|
|
563
275
|
freParams
|
|
564
276
|
)
|
|
565
277
|
|
|
@@ -578,7 +290,7 @@ Now let's console log each of those values to check everything is working
|
|
|
578
290
|
|
|
579
291
|
```
|
|
580
292
|
|
|
581
|
-
###
|
|
293
|
+
### 6.2 Set metadata in the fixed rate exchange NFT
|
|
582
294
|
```Typescript
|
|
583
295
|
const nft = new Nft(web3)
|
|
584
296
|
|
|
@@ -621,11 +333,11 @@ Now let's console log the DID to check everything is working
|
|
|
621
333
|
})
|
|
622
334
|
```
|
|
623
335
|
|
|
624
|
-
###
|
|
336
|
+
### 6.3 Marketplace displays fixed rate asset for sale
|
|
625
337
|
```Typescript
|
|
626
|
-
const fixedRate = new FixedRateExchange(
|
|
338
|
+
const fixedRate = new FixedRateExchange(freAddress, web3)
|
|
627
339
|
const oceanAmount = await (
|
|
628
|
-
await fixedRate.
|
|
340
|
+
await fixedRate.calcBaseInGivenDatatokensOut(freId, '1')
|
|
629
341
|
).baseTokenAmount
|
|
630
342
|
```
|
|
631
343
|
Now that the market has fetched those values it can display the asset on the front end. In our case we will just console log the results:
|
|
@@ -634,7 +346,7 @@ Now that the market has fetched those values it can display the asset on the fro
|
|
|
634
346
|
|
|
635
347
|
```
|
|
636
348
|
|
|
637
|
-
###
|
|
349
|
+
### 6.4 Consumer buys a fixed rate asset data asset, and downloads it
|
|
638
350
|
```Typescript
|
|
639
351
|
const datatoken = new Datatoken(web3)
|
|
640
352
|
const DATATOKEN_AMOUNT = '10000'
|
|
@@ -653,22 +365,23 @@ Let's do a quick check of the consumer ETH balance before the swap
|
|
|
653
365
|
console.log(`Consumer ${FRE_NFT_SYMBOL} balance before swap: ${consumerDTBalance}`)
|
|
654
366
|
|
|
655
367
|
```
|
|
656
|
-
Before we call the contract we have to call `approve` so that the contract can move our tokens. This is standard when using any ERC20
|
|
368
|
+
Before we call the contract we have to call `approve` so that the contract can move our tokens. This is standard when using any ERC20 Datatokens
|
|
657
369
|
```Typescript
|
|
658
|
-
await approve(web3, consumerAccount, addresses.Ocean, freAddress, '100')
|
|
370
|
+
await approve(web3, config, consumerAccount, addresses.Ocean, freAddress, '100')
|
|
659
371
|
await approve(
|
|
660
372
|
web3,
|
|
373
|
+
config,
|
|
661
374
|
publisherAccount,
|
|
662
375
|
freDatatokenAddress,
|
|
663
376
|
freAddress,
|
|
664
377
|
DATATOKEN_AMOUNT
|
|
665
378
|
)
|
|
666
379
|
|
|
667
|
-
const fixedRate = new FixedRateExchange(
|
|
380
|
+
const fixedRate = new FixedRateExchange(freAddress, web3)
|
|
668
381
|
```
|
|
669
382
|
Now we can make the contract call
|
|
670
383
|
```Typescript
|
|
671
|
-
await fixedRate.
|
|
384
|
+
await fixedRate.buyDatatokens(consumerAccount, freId, '1', '2')
|
|
672
385
|
|
|
673
386
|
consumerOCEANBalance = await balance(web3, addresses.Ocean, consumerAccount)
|
|
674
387
|
console.log(`Consumer OCEAN balance after swap: ${consumerOCEANBalance}`)
|
|
@@ -742,9 +455,9 @@ Lets check that the download URL was successfully received
|
|
|
742
455
|
|
|
743
456
|
```
|
|
744
457
|
|
|
745
|
-
##
|
|
458
|
+
## 7. Publish Data NFT and a Datatoken with a dispenser
|
|
746
459
|
|
|
747
|
-
###
|
|
460
|
+
### 7.1 Publish a dataset (create NFT + Datatoken) with a dispenser
|
|
748
461
|
```Typescript
|
|
749
462
|
const factory = new NftFactory(addresses.ERC721Factory, web3)
|
|
750
463
|
|
|
@@ -757,7 +470,7 @@ Lets check that the download URL was successfully received
|
|
|
757
470
|
owner: publisherAccount
|
|
758
471
|
}
|
|
759
472
|
|
|
760
|
-
const
|
|
473
|
+
const datatokenParams: DatatokenCreateParams = {
|
|
761
474
|
templateIndex: 1,
|
|
762
475
|
cap: '100000',
|
|
763
476
|
feeAmount: '0',
|
|
@@ -775,10 +488,10 @@ Lets check that the download URL was successfully received
|
|
|
775
488
|
allowedSwapper: ZERO_ADDRESS
|
|
776
489
|
}
|
|
777
490
|
|
|
778
|
-
const tx = await factory.
|
|
491
|
+
const tx = await factory.createNftWithDatatokenWithDispenser(
|
|
779
492
|
publisherAccount,
|
|
780
493
|
nftParams,
|
|
781
|
-
|
|
494
|
+
datatokenParams,
|
|
782
495
|
dispenserParams
|
|
783
496
|
)
|
|
784
497
|
|
|
@@ -794,7 +507,7 @@ Lets check that we managed to received all of those values without any problems
|
|
|
794
507
|
|
|
795
508
|
```
|
|
796
509
|
|
|
797
|
-
###
|
|
510
|
+
### 7.2 Set metadata in the dispenser NFT
|
|
798
511
|
```Typescript
|
|
799
512
|
const nft = new Nft(web3)
|
|
800
513
|
|
|
@@ -834,10 +547,10 @@ Now we need to encrypt file(s) using provider
|
|
|
834
547
|
|
|
835
548
|
```
|
|
836
549
|
|
|
837
|
-
###
|
|
550
|
+
### 7.3 Consumer gets a dispenser data asset, and downloads it
|
|
838
551
|
```Typescript
|
|
839
552
|
const datatoken = new Datatoken(web3)
|
|
840
|
-
const dispenser = new Dispenser(
|
|
553
|
+
const dispenser = new Dispenser(addresses.Dispenser, web3)
|
|
841
554
|
|
|
842
555
|
let consumerDTBalance = await balance(
|
|
843
556
|
web3,
|
package/README.md
CHANGED
|
@@ -14,8 +14,7 @@
|
|
|
14
14
|
With ocean.js, you can:
|
|
15
15
|
|
|
16
16
|
- **Publish** data services: downloadable files or compute-to-data. Create an ERC721 **data NFT** for each service, and ERC20 **datatoken** for access (1.0 datatokens to access).
|
|
17
|
-
- **Sell** datatokens
|
|
18
|
-
- **Stake OCEAN** on datatoken pools
|
|
17
|
+
- **Sell** datatokens for a fixed price. Sell data NFTs.
|
|
19
18
|
- **Transfer** data NFTs & datatokens to another owner, and **all other ERC721 & ERC20 actions** using [web3.js](https://web3js.readthedocs.io/en/v1.2.9/web3-eth-contract.html) etc.
|
|
20
19
|
|
|
21
20
|
ocean.js is part of the [Ocean Protocol](https://oceanprotocol.com) toolset.
|
|
@@ -23,8 +22,7 @@ ocean.js is part of the [Ocean Protocol](https://oceanprotocol.com) toolset.
|
|
|
23
22
|
This is in alpha state. If you run into problems, please open up a [new issue](https://github.com/oceanprotocol/ocean.js/issues/new?assignees=&labels=bug&template=bug_report.md&title=).
|
|
24
23
|
|
|
25
24
|
- [📚 Prerequisites](#-prerequisites)
|
|
26
|
-
- [🏗 Installation](#-installation)
|
|
27
|
-
- [📖 Learn More](#-learn-more)
|
|
25
|
+
- [🏗 Installation & Usage](#-installation--usage)
|
|
28
26
|
- [🦑 Development](#-development)
|
|
29
27
|
- [✨ Code Style](#-code-style)
|
|
30
28
|
- [👩🔬 Testing](#-testing)
|
|
@@ -33,7 +31,7 @@ This is in alpha state. If you run into problems, please open up a [new issue](h
|
|
|
33
31
|
- [🛳 Production](#-production)
|
|
34
32
|
- [⬆️ Releases](#️-releases)
|
|
35
33
|
- [Production](#production)
|
|
36
|
-
- [Pre-
|
|
34
|
+
- [Pre-Releases](#pre-releases)
|
|
37
35
|
- [🏛 License](#-license)
|
|
38
36
|
|
|
39
37
|
## 📚 Prerequisites
|
|
@@ -42,12 +40,11 @@ This is in alpha state. If you run into problems, please open up a [new issue](h
|
|
|
42
40
|
- Docker ([Managed as a non-root user](https://docs.docker.com/engine/install/linux-postinstall/))
|
|
43
41
|
- A Unix based operating system (Mac or Linux)
|
|
44
42
|
|
|
45
|
-
## 🏗 Installation
|
|
43
|
+
## 🏗 Installation & Usage
|
|
46
44
|
|
|
47
45
|
```bash
|
|
48
46
|
npm install @oceanprotocol/lib
|
|
49
47
|
```
|
|
50
|
-
### 📖 Learn more
|
|
51
48
|
|
|
52
49
|
- Checkout our [code examples](CodeExamples.md) to see how you can use ocean.js.
|
|
53
50
|
- Refer to the [Ocean Protocol documentation](https://docs.oceanprotocol.com/) for more guides and tutorials.
|