From e912b9f2bd513a02eb1e68bafbc73db710715c7a Mon Sep 17 00:00:00 2001 From: alexcos20 Date: Fri, 16 Oct 2020 03:27:20 -0700 Subject: [PATCH 1/2] bump ocean --- example/package-lock.json | 2 -- package-lock.json | 14 +++++++------- package.json | 2 +- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/example/package-lock.json b/example/package-lock.json index 0d36339..bd20b19 100644 --- a/example/package-lock.json +++ b/example/package-lock.json @@ -1403,9 +1403,7 @@ "@oceanprotocol/react": { "version": "file:..", "requires": { - "@oceanprotocol/lib": "^0.5.6", "axios": "^0.20.0", - "decimal.js": "^10.2.1", "web3": "^1.3.0", "web3modal": "^1.9.0" }, diff --git a/package-lock.json b/package-lock.json index 17564c7..4d6823a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1516,17 +1516,17 @@ } }, "@oceanprotocol/contracts": { - "version": "0.5.5", - "resolved": "https://registry.npmjs.org/@oceanprotocol/contracts/-/contracts-0.5.5.tgz", - "integrity": "sha512-Omwlh3KxPm2JOuLd6DW4teAQhGaIv0fRTopCvctey0XGsf3DcbJpwS0A0YfgLQnvCyyVMKsiq90YCqpJ3SO/cw==" + "version": "0.5.6", + "resolved": "https://registry.npmjs.org/@oceanprotocol/contracts/-/contracts-0.5.6.tgz", + "integrity": "sha512-LING+GvW37I0L40rZdPCZ1SvcZurDSGGhT0WOVPNO8oyh2C3bXModDBNE4+gCFa8pTbQBOc4ot1/Zoj9PfT/zA==" }, "@oceanprotocol/lib": { - "version": "0.6.0", - "resolved": "https://registry.npmjs.org/@oceanprotocol/lib/-/lib-0.6.0.tgz", - "integrity": "sha512-5Kv6oVV7nneeVoT79fAQh93Ksb4Zg0TjjbVutMIYDt9kB8/Iwc/5NYU88unaz4XHX5zBl5rqnwfWoZMRDaI7hA==", + "version": "0.6.4", + "resolved": "https://registry.npmjs.org/@oceanprotocol/lib/-/lib-0.6.4.tgz", + "integrity": "sha512-yNaeoTXjRmhXrDgRMchxmS49zqWI23e50W49OsOyEt+RqDKpbBBBlqzyeNcI0KU3vwnwhV+CH7nqSDUbOothow==", "requires": { "@ethereum-navigator/navigator": "^0.5.0", - "@oceanprotocol/contracts": "^0.5.5", + "@oceanprotocol/contracts": "^0.5.6", "decimal.js": "^10.2.0", "fs": "0.0.1-security", "lzma": "^2.3.2", diff --git a/package.json b/package.json index f88535e..f6ead11 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,7 @@ "dist/" ], "dependencies": { - "@oceanprotocol/lib": "^0.6.0", + "@oceanprotocol/lib": "^0.6.4", "axios": "^0.20.0", "decimal.js": "^10.2.1", "web3": "^1.3.0", From 81b190dd9340af8818e78d017aba00c19af5a9b7 Mon Sep 17 00:00:00 2001 From: alexcos20 Date: Fri, 16 Oct 2020 03:27:33 -0700 Subject: [PATCH 2/2] switch to first pool --- src/utils/dtUtils.ts | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/src/utils/dtUtils.ts b/src/utils/dtUtils.ts index c875f9b..9c8b638 100644 --- a/src/utils/dtUtils.ts +++ b/src/utils/dtUtils.ts @@ -86,11 +86,38 @@ export async function getCheapestExchange( } } +export async function getFirstPool( + ocean: Ocean, + dataTokenAddress: string +): Promise { + if (!ocean || !dataTokenAddress) return null + + const tokenPools = await ocean.pool.searchPoolforDT(dataTokenAddress) + + if (tokenPools === undefined || tokenPools.length === 0) { + return { + address: '', + price: 0 + } + } + const firstPoolAddress = tokenPools[0] + const firstPoolPrice = await ocean.pool.getOceanNeeded(firstPoolAddress, '1') + const oceanReserve = await ocean.pool.getOceanReserve(firstPoolAddress) + const dtReserve = await ocean.pool.getDTReserve(firstPoolAddress) + + return { + address: firstPoolAddress, + price: Number(firstPoolPrice), + ocean: Number(oceanReserve), + datatoken: Number(dtReserve) + } +} + export async function getBestDataTokenPrice( ocean: Ocean, dataTokenAddress: string ): Promise { - const cheapestPool = await getCheapestPool(ocean, dataTokenAddress) + const cheapestPool = await getFirstPool(ocean, dataTokenAddress) const cheapestExchange = await getCheapestExchange(ocean, dataTokenAddress) Decimal.set({ precision: 5 })