mirror of
https://github.com/oceanprotocol/ocean.js.git
synced 2024-11-26 20:39:05 +01:00
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] <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](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] <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 <>
This commit is contained in:
parent
ed0d04f92c
commit
ad0e724e68
4
.github/workflows/ci.yml
vendored
4
.github/workflows/ci.yml
vendored
@ -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
|
||||
|
@ -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}`)
|
||||
<!--
|
||||
// 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')
|
||||
)
|
||||
-->
|
||||
|
||||
```
|
||||
|
||||
|
14
package-lock.json
generated
14
package-lock.json
generated
@ -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",
|
||||
|
@ -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",
|
||||
|
@ -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[]
|
||||
}
|
||||
|
@ -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
src/contracts/ve/VeFeeEstimate.ts
Normal file
27
src/contracts/ve/VeFeeEstimate.ts
Normal file
@ -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
|
||||
}
|
||||
}
|
@ -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}`)
|
||||
/// <!--
|
||||
// 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')
|
||||
)
|
||||
/// -->
|
||||
}) ///
|
||||
/// ```
|
||||
|
||||
|
@ -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
|
||||
/// <!--
|
||||
// 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',
|
||||
|
@ -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,
|
||||
@ -11,7 +12,9 @@ import {
|
||||
getHash,
|
||||
Nft,
|
||||
downloadFile,
|
||||
ZERO_ADDRESS
|
||||
ZERO_ADDRESS,
|
||||
calculateEstimatedGas,
|
||||
sendTx
|
||||
} from '../../src'
|
||||
import { ProviderFees, DatatokenCreateParams, DDO, Files } from '../../src/@types'
|
||||
|
||||
@ -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 () => {
|
||||
|
@ -9,7 +9,8 @@ import {
|
||||
sendTx,
|
||||
calculateEstimatedGas,
|
||||
NftFactory,
|
||||
VeAllocate
|
||||
VeAllocate,
|
||||
VeFeeEstimate
|
||||
} from '../../src'
|
||||
|
||||
describe('veOcean tests', async () => {
|
||||
@ -18,6 +19,7 @@ describe('veOcean tests', async () => {
|
||||
let nftFactory
|
||||
let veOcean: VeOcean
|
||||
let veFeeDistributor: VeFeeDistributor
|
||||
let veFeeEstimate: VeFeeEstimate
|
||||
let veAllocate: VeAllocate
|
||||
let ownerAccount: string
|
||||
let Alice: string
|
||||
@ -78,6 +80,7 @@ describe('veOcean tests', async () => {
|
||||
veOcean = new VeOcean(addresses.veOCEAN, web3)
|
||||
veFeeDistributor = new VeFeeDistributor(addresses.veFeeDistributor, web3)
|
||||
veAllocate = new VeAllocate(addresses.veAllocate, web3)
|
||||
veFeeEstimate = new VeFeeEstimate(addresses.veFeeEstimate, web3)
|
||||
nftFactory = new NftFactory(addresses.ERC721Factory, web3)
|
||||
})
|
||||
|
||||
@ -215,4 +218,10 @@ describe('veOcean tests', async () => {
|
||||
nftAllocation + ' should be 2000'
|
||||
)
|
||||
})
|
||||
|
||||
it('Alice should be able to estimate her claim amount', async () => {
|
||||
const estimatedClaim = await veFeeEstimate.estimateClaim(Alice)
|
||||
// since we have no rewards, we are expecting 0
|
||||
assert(estimatedClaim === '0')
|
||||
})
|
||||
})
|
||||
|
Loading…
x
Reference in New Issue
Block a user