From ad0e724e68749679976d62760f96b21cbb95816c Mon Sep 17 00:00:00 2001 From: Alex Coseru Date: Mon, 12 Sep 2022 18:20:21 +0300 Subject: [PATCH] Feature/add ve fee estimate (#1606) * bump to contracts 1.1.4 * add estimateClaim * fix * Bump decimal.js from 10.3.1 to 10.4.0 (#1598) Bumps [decimal.js](https://github.com/MikeMcl/decimal.js) from 10.3.1 to 10.4.0. - [Release notes](https://github.com/MikeMcl/decimal.js/releases) - [Changelog](https://github.com/MikeMcl/decimal.js/blob/master/CHANGELOG.md) - [Commits](https://github.com/MikeMcl/decimal.js/compare/v10.3.1...v10.4.0) --- updated-dependencies: - dependency-name: decimal.js dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Bump @typescript-eslint/eslint-plugin from 5.33.1 to 5.36.2 (#1601) Bumps [@typescript-eslint/eslint-plugin](https://github.com/typescript-eslint/typescript-eslint/tree/HEAD/packages/eslint-plugin) from 5.33.1 to 5.36.2. - [Release notes](https://github.com/typescript-eslint/typescript-eslint/releases) - [Changelog](https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/CHANGELOG.md) - [Commits](https://github.com/typescript-eslint/typescript-eslint/commits/v5.36.2/packages/eslint-plugin) --- updated-dependencies: - dependency-name: "@typescript-eslint/eslint-plugin" dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Bump eslint from 8.19.0 to 8.23.0 (#1602) Bumps [eslint](https://github.com/eslint/eslint) from 8.19.0 to 8.23.0. - [Release notes](https://github.com/eslint/eslint/releases) - [Changelog](https://github.com/eslint/eslint/blob/main/CHANGELOG.md) - [Commits](https://github.com/eslint/eslint/compare/v8.19.0...v8.23.0) --- updated-dependencies: - dependency-name: eslint dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * add graphql type (#1607) * add graphql type * Updating CodeExamples.md Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: GitHub Actions Bot <> --- .github/workflows/ci.yml | 4 +- CodeExamples.md | 46 ++++++++++++++++++- package-lock.json | 14 +++--- package.json | 2 +- src/@types/File.ts | 23 +++++++++- src/contracts/index.ts | 1 + src/contracts/ve/VeFeeEstimate.ts | 27 +++++++++++ test/integration/CodeExamples.test.ts | 46 ++++++++++++++++++- test/integration/ComputeFlow.test.ts | 39 +++++++++++++++- .../SimplePublishConsumeFlow.test.ts | 39 +++++++++++++++- test/unit/veOcean.test.ts | 11 ++++- 11 files changed, 235 insertions(+), 17 deletions(-) create mode 100644 src/contracts/ve/VeFeeEstimate.ts diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5b51e5fe..c7f1126b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -61,7 +61,7 @@ jobs: run: | bash -x start_ocean.sh --no-aquarius --no-elasticsearch --no-provider --no-dashboard 2>&1 > start_ocean.log & env: - CONTRACTS_VERSION: v1.1.3 + CONTRACTS_VERSION: v1.1.4 - run: npm ci - name: Wait for contracts deployment working-directory: ${{ github.workspace }}/barge @@ -118,6 +118,8 @@ jobs: working-directory: ${{ github.workspace }}/barge run: | bash -x start_ocean.sh --with-provider2 --no-dashboard --with-c2d 2>&1 > start_ocean.log & + env: + CONTRACTS_VERSION: v1.1.3 - run: npm ci - run: npm run build:metadata diff --git a/CodeExamples.md b/CodeExamples.md index 50801a50..d84982f9 100644 --- a/CodeExamples.md +++ b/CodeExamples.md @@ -85,6 +85,7 @@ Start by importing all of the necessary dependencies ```Typescript +import { AbiItem } from 'web3-utils' import { SHA256 } from 'crypto-js' import { approve, @@ -106,7 +107,9 @@ import { ProviderFees, ProviderInstance, transfer, - ZERO_ADDRESS + ZERO_ADDRESS, + calculateEstimatedGas, + sendTx } from '../../src' import { getAddresses, getTestConfig, web3 } from '../config' ``` @@ -202,7 +205,13 @@ As we go along it's a good idea to console log the values so that you check they ``` ## 5. Initialize accounts and deploy contracts - ### 5.1 Initialize accounts + ### 5.1 Next, lets get the address of the deployed contracts +```Typescript + addresses = getAddresses() + +``` + + ### 5.2 Initialize accounts ```Typescript const accounts = await web3.eth.getAccounts() publisherAccount = accounts[0] @@ -214,6 +223,39 @@ Again, lets console log the values so that we can check that they have been save console.log(`Publisher account address: ${publisherAccount}`) console.log(`Consumer account address: ${consumerAccount}`) console.log(`Staker account address: ${stakerAccount}`) + ``` diff --git a/package-lock.json b/package-lock.json index 66b39c29..8f584507 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "2.0.0", "license": "Apache-2.0", "dependencies": { - "@oceanprotocol/contracts": "^1.1.3", + "@oceanprotocol/contracts": "^1.1.4", "bignumber.js": "^9.0.2", "cross-fetch": "^3.1.5", "crypto-js": "^4.1.1", @@ -2615,9 +2615,9 @@ } }, "node_modules/@oceanprotocol/contracts": { - "version": "1.1.3", - "resolved": "https://registry.npmjs.org/@oceanprotocol/contracts/-/contracts-1.1.3.tgz", - "integrity": "sha512-pn0rm4QKF8sVfDeJVlt18TV4Qj5oGgR/qQNO7O0GO2DQ3q8KHXRS15uRjmLTr5wW1kGcCHcTqEndXEEC7Elzkw==" + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/@oceanprotocol/contracts/-/contracts-1.1.4.tgz", + "integrity": "sha512-fIJjtyj1fxF3GNaITUDaUJbQ2FBCLqB6Hlg72k5SzBK2//yuSPfdZVAqomul0qQjgiKl0jlJRmWVpfer/a5z2g==" }, "node_modules/@octokit/auth-token": { "version": "3.0.1", @@ -19612,9 +19612,9 @@ } }, "@oceanprotocol/contracts": { - "version": "1.1.3", - "resolved": "https://registry.npmjs.org/@oceanprotocol/contracts/-/contracts-1.1.3.tgz", - "integrity": "sha512-pn0rm4QKF8sVfDeJVlt18TV4Qj5oGgR/qQNO7O0GO2DQ3q8KHXRS15uRjmLTr5wW1kGcCHcTqEndXEEC7Elzkw==" + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/@oceanprotocol/contracts/-/contracts-1.1.4.tgz", + "integrity": "sha512-fIJjtyj1fxF3GNaITUDaUJbQ2FBCLqB6Hlg72k5SzBK2//yuSPfdZVAqomul0qQjgiKl0jlJRmWVpfer/a5z2g==" }, "@octokit/auth-token": { "version": "3.0.1", diff --git a/package.json b/package.json index 25aeb048..4dd16ee4 100644 --- a/package.json +++ b/package.json @@ -49,7 +49,7 @@ "web3": "^1.7.4" }, "dependencies": { - "@oceanprotocol/contracts": "^1.1.3", + "@oceanprotocol/contracts": "^1.1.4", "bignumber.js": "^9.0.2", "cross-fetch": "^3.1.5", "crypto-js": "^4.1.1", diff --git a/src/@types/File.ts b/src/@types/File.ts index c48bfad6..481606f7 100644 --- a/src/@types/File.ts +++ b/src/@types/File.ts @@ -20,8 +20,29 @@ export interface UrlFile { method: string } +export interface GraphqlQuery { + type: 'graphql' + + /** + * @type {number} + */ + index?: number + + /** + * Endpoint URL + * @type {string} + */ + url: string + + /** + * query + * @type {string} + */ + query: string +} + export interface Files { nftAddress: string datatokenAddress: string - files: UrlFile[] + files: UrlFile[] | GraphqlQuery[] } diff --git a/src/contracts/index.ts b/src/contracts/index.ts index 2db33363..d1b99fce 100644 --- a/src/contracts/index.ts +++ b/src/contracts/index.ts @@ -8,6 +8,7 @@ export * from './NFT' export * from './NFTFactory' export * from './ve/VeOcean' export * from './ve/VeFeeDistributor' +export * from './ve/VeFeeEstimate' export * from './ve/VeAllocate' export * from './df/DfRewards' export * from './df/DfStrategyV1' diff --git a/src/contracts/ve/VeFeeEstimate.ts b/src/contracts/ve/VeFeeEstimate.ts new file mode 100644 index 00000000..ea2348c1 --- /dev/null +++ b/src/contracts/ve/VeFeeEstimate.ts @@ -0,0 +1,27 @@ +import { AbiItem } from 'web3-utils' +import veFeeEstimate from '@oceanprotocol/contracts/artifacts/contracts/ve/veFeeEstimate.vy/veFeeEstimate.json' +import { SmartContractWithAddress } from '../SmartContractWithAddress' +import { VeOcean } from './VeOcean' +/** + * Provides an interface for veOcean contract + */ +export class VeFeeEstimate extends SmartContractWithAddress { + getDefaultAbi(): AbiItem | AbiItem[] { + return veFeeEstimate.abi as AbiItem[] + } + + /** + * estimateClaim + * @param {String} userAddress user address + * @return {Promise} + */ + public async estimateClaim(userAddress: string): Promise { + const amount = await this.contract.methods.estimateClaim(userAddress).call() + const veOcean = new VeOcean( + await this.contract.methods.voting_escrow().call(), + this.web3 + ) + const amountFormated = await this.unitsToAmount(await veOcean.getToken(), amount) + return amountFormated + } +} diff --git a/test/integration/CodeExamples.test.ts b/test/integration/CodeExamples.test.ts index a7a4e773..9e0f48e4 100644 --- a/test/integration/CodeExamples.test.ts +++ b/test/integration/CodeExamples.test.ts @@ -85,6 +85,7 @@ /// ```Typescript import { assert } from 'chai' +import { AbiItem } from 'web3-utils' import { SHA256 } from 'crypto-js' import { approve, @@ -106,7 +107,9 @@ import { ProviderFees, ProviderInstance, transfer, - ZERO_ADDRESS + ZERO_ADDRESS, + calculateEstimatedGas, + sendTx } from '../../src' import { getAddresses, getTestConfig, web3 } from '../config' /// ``` @@ -202,7 +205,13 @@ describe('Marketplace flow tests', async () => { /// ``` /// ## 5. Initialize accounts and deploy contracts - it('5.1 Initialize accounts', async () => { + it('5.1 Next, lets get the address of the deployed contracts', async () => { + /// ```Typescript + addresses = getAddresses() + }) /// + /// ``` + + it('5.2 Initialize accounts', async () => { /// ```Typescript const accounts = await web3.eth.getAccounts() publisherAccount = accounts[0] @@ -214,6 +223,39 @@ describe('Marketplace flow tests', async () => { console.log(`Publisher account address: ${publisherAccount}`) console.log(`Consumer account address: ${consumerAccount}`) console.log(`Staker account address: ${stakerAccount}`) + /// }) /// /// ``` diff --git a/test/integration/ComputeFlow.test.ts b/test/integration/ComputeFlow.test.ts index feef4687..44a7bbd5 100644 --- a/test/integration/ComputeFlow.test.ts +++ b/test/integration/ComputeFlow.test.ts @@ -1,5 +1,6 @@ import { assert } from 'chai' import { SHA256 } from 'crypto-js' +import { AbiItem } from 'web3-utils' import { web3, getTestConfig, getAddresses } from '../config' import { Config, @@ -10,7 +11,9 @@ import { Datatoken, Nft, ZERO_ADDRESS, - approveWei + approveWei, + calculateEstimatedGas, + sendTx } from '../../src' import { DatatokenCreateParams, @@ -360,6 +363,40 @@ describe('Simple compute tests', async () => { const accounts = await web3.eth.getAccounts() publisherAccount = accounts[0] consumerAccount = accounts[1] + // mint Ocean + ///