Skip to content

Commit

Permalink
Feature/add ve fee estimate (#1606)
Browse files Browse the repository at this point in the history
* 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](MikeMcl/decimal.js@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] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
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] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
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](eslint/eslint@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] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
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] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: GitHub Actions Bot <>
  • Loading branch information
alexcos20 and dependabot[bot] committed Sep 12, 2022
1 parent ed0d04f commit ad0e724
Show file tree
Hide file tree
Showing 11 changed files with 235 additions and 17 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
46 changes: 44 additions & 2 deletions CodeExamples.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -106,7 +107,9 @@ import {
ProviderFees,
ProviderInstance,
transfer,
ZERO_ADDRESS
ZERO_ADDRESS,
calculateEstimatedGas,
sendTx
} from '../../src'
import { getAddresses, getTestConfig, web3 } from '../config'
```
Expand Down Expand Up @@ -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]
Expand All @@ -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}`)
<!--
// mint ocean to publisherAccount
const minAbi = [
{
constant: false,
inputs: [
{ name: 'to', type: 'address' },
{ name: 'value', type: 'uint256' }
],
name: 'mint',
outputs: [{ name: '', type: 'bool' }],
payable: false,
stateMutability: 'nonpayable',
type: 'function'
}
] as AbiItem[]
const tokenContract = new web3.eth.Contract(minAbi, addresses.Ocean)
const estGas = await calculateEstimatedGas(
publisherAccount,
tokenContract.methods.mint,
publisherAccount,
web3.utils.toWei('1000')
)
await sendTx(
publisherAccount,
estGas,
web3,
1,
tokenContract.methods.mint,
publisherAccount,
web3.utils.toWei('1000')
)
-->

```

Expand Down
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
23 changes: 22 additions & 1 deletion src/@types/File.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[]
}
1 change: 1 addition & 0 deletions src/contracts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
27 changes: 27 additions & 0 deletions src/contracts/ve/VeFeeEstimate.ts
Original file line number Diff line number Diff line change
@@ -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<string>}
*/
public async estimateClaim(userAddress: string): Promise<string> {
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
}
}
46 changes: 44 additions & 2 deletions test/integration/CodeExamples.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@

/// ```Typescript
import { assert } from 'chai'
import { AbiItem } from 'web3-utils'
import { SHA256 } from 'crypto-js'
import {
approve,
Expand All @@ -106,7 +107,9 @@ import {
ProviderFees,
ProviderInstance,
transfer,
ZERO_ADDRESS
ZERO_ADDRESS,
calculateEstimatedGas,
sendTx
} from '../../src'
import { getAddresses, getTestConfig, web3 } from '../config'
/// ```
Expand Down Expand Up @@ -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]
Expand All @@ -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}`)
/// <!--
// mint ocean to publisherAccount
const minAbi = [
{
constant: false,
inputs: [
{ name: 'to', type: 'address' },
{ name: 'value', type: 'uint256' }
],
name: 'mint',
outputs: [{ name: '', type: 'bool' }],
payable: false,
stateMutability: 'nonpayable',
type: 'function'
}
] as AbiItem[]
const tokenContract = new web3.eth.Contract(minAbi, addresses.Ocean)
const estGas = await calculateEstimatedGas(
publisherAccount,
tokenContract.methods.mint,
publisherAccount,
web3.utils.toWei('1000')
)
await sendTx(
publisherAccount,
estGas,
web3,
1,
tokenContract.methods.mint,
publisherAccount,
web3.utils.toWei('1000')
)
/// -->
}) ///
/// ```

Expand Down
39 changes: 38 additions & 1 deletion test/integration/ComputeFlow.test.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -10,7 +11,9 @@ import {
Datatoken,
Nft,
ZERO_ADDRESS,
approveWei
approveWei,
calculateEstimatedGas,
sendTx
} from '../../src'
import {
DatatokenCreateParams,
Expand Down Expand Up @@ -360,6 +363,40 @@ describe('Simple compute tests', async () => {
const accounts = await web3.eth.getAccounts()
publisherAccount = accounts[0]
consumerAccount = accounts[1]
// mint Ocean
/// <!--
// mint ocean to publisherAccount
const minAbi = [
{
constant: false,
inputs: [
{ name: 'to', type: 'address' },
{ name: 'value', type: 'uint256' }
],
name: 'mint',
outputs: [{ name: '', type: 'bool' }],
payable: false,
stateMutability: 'nonpayable',
type: 'function'
}
] as AbiItem[]
const tokenContract = new web3.eth.Contract(minAbi, addresses.Ocean)
const estGas = await calculateEstimatedGas(
publisherAccount,
tokenContract.methods.mint,
publisherAccount,
web3.utils.toWei('1000')
)
await sendTx(
publisherAccount,
estGas,
web3,
1,
tokenContract.methods.mint,
publisherAccount,
web3.utils.toWei('1000')
)

ddoWith1mTimeoutId = await createAsset(
'D1Min',
'D1M',
Expand Down
39 changes: 38 additions & 1 deletion test/integration/SimplePublishConsumeFlow.test.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -11,7 +12,9 @@ import {
getHash,
Nft,
downloadFile,
ZERO_ADDRESS
ZERO_ADDRESS,
calculateEstimatedGas,
sendTx
} from '../../src'
import { ProviderFees, DatatokenCreateParams, DDO, Files } from '../../src/@types'

Expand Down Expand Up @@ -74,6 +77,40 @@ describe('Simple Publish & consume test', async () => {
const accounts = await web3.eth.getAccounts()
publisherAccount = accounts[0]
consumerAccount = accounts[1]

// mint Ocean tokens
/// <!--
// mint ocean to publisherAccount
const minAbi = [
{
constant: false,
inputs: [
{ name: 'to', type: 'address' },
{ name: 'value', type: 'uint256' }
],
name: 'mint',
outputs: [{ name: '', type: 'bool' }],
payable: false,
stateMutability: 'nonpayable',
type: 'function'
}
] as AbiItem[]
const tokenContract = new web3.eth.Contract(minAbi, addresses.Ocean)
const estGas = await calculateEstimatedGas(
publisherAccount,
tokenContract.methods.mint,
publisherAccount,
web3.utils.toWei('1000')
)
await sendTx(
publisherAccount,
estGas,
web3,
1,
tokenContract.methods.mint,
publisherAccount,
web3.utils.toWei('1000')
)
})

it('should publish a dataset (create NFT + Datatoken)', async () => {
Expand Down

0 comments on commit ad0e724

Please sign in to comment.