mirror of
https://github.com/oceanprotocol/ocean.js.git
synced 2024-11-26 20:39:05 +01:00
update to contracts alpha.19 (#1286)
This commit is contained in:
parent
bad1fd5504
commit
91a4431938
14
package-lock.json
generated
14
package-lock.json
generated
@ -9,7 +9,7 @@
|
||||
"version": "1.0.0-next.17",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"@oceanprotocol/contracts": "1.0.0-alpha.18",
|
||||
"@oceanprotocol/contracts": "1.0.0-alpha.19",
|
||||
"bignumber.js": "^9.0.2",
|
||||
"cross-fetch": "^3.1.5",
|
||||
"crypto-js": "^4.1.1",
|
||||
@ -3033,9 +3033,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@oceanprotocol/contracts": {
|
||||
"version": "1.0.0-alpha.18",
|
||||
"resolved": "https://registry.npmjs.org/@oceanprotocol/contracts/-/contracts-1.0.0-alpha.18.tgz",
|
||||
"integrity": "sha512-0MFX5n71dke095drRKXoCvF25FrAuraAcNyuUqps0WsVyM7N+jIdiJsF4u26/TrfYzNV/Y/0zRmi6bR4mTA7KA==",
|
||||
"version": "1.0.0-alpha.19",
|
||||
"resolved": "https://registry.npmjs.org/@oceanprotocol/contracts/-/contracts-1.0.0-alpha.19.tgz",
|
||||
"integrity": "sha512-3E4eMo2lMyWMjiGk5dvSZvs/QNq7GSAPPzfMbxVLCdjfyP7kvVVVgn0pxabQtexkK4NK7tpNdA+IbsJaM0BBdw==",
|
||||
"dependencies": {
|
||||
"@openzeppelin/contracts": "^4.3.3",
|
||||
"@openzeppelin/test-helpers": "^0.5.15",
|
||||
@ -27682,9 +27682,9 @@
|
||||
}
|
||||
},
|
||||
"@oceanprotocol/contracts": {
|
||||
"version": "1.0.0-alpha.18",
|
||||
"resolved": "https://registry.npmjs.org/@oceanprotocol/contracts/-/contracts-1.0.0-alpha.18.tgz",
|
||||
"integrity": "sha512-0MFX5n71dke095drRKXoCvF25FrAuraAcNyuUqps0WsVyM7N+jIdiJsF4u26/TrfYzNV/Y/0zRmi6bR4mTA7KA==",
|
||||
"version": "1.0.0-alpha.19",
|
||||
"resolved": "https://registry.npmjs.org/@oceanprotocol/contracts/-/contracts-1.0.0-alpha.19.tgz",
|
||||
"integrity": "sha512-3E4eMo2lMyWMjiGk5dvSZvs/QNq7GSAPPzfMbxVLCdjfyP7kvVVVgn0pxabQtexkK4NK7tpNdA+IbsJaM0BBdw==",
|
||||
"requires": {
|
||||
"@openzeppelin/contracts": "^4.3.3",
|
||||
"@openzeppelin/test-helpers": "^0.5.15",
|
||||
|
@ -57,7 +57,7 @@
|
||||
"web3": "^1.7.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@oceanprotocol/contracts": "1.0.0-alpha.18",
|
||||
"@oceanprotocol/contracts": "1.0.0-alpha.19",
|
||||
"bignumber.js": "^9.0.2",
|
||||
"cross-fetch": "^3.1.5",
|
||||
"crypto-js": "^4.1.1",
|
||||
|
@ -9,3 +9,9 @@ export interface Erc20CreateParams {
|
||||
name?: string
|
||||
symbol?: string
|
||||
}
|
||||
|
||||
export interface ConsumeMarketFee {
|
||||
consumeMarketFeeAddress: string
|
||||
consumeMarketFeeToken: string // address of the token marketplace wants to add fee on top
|
||||
consumeMarketFeeAmount: string
|
||||
}
|
||||
|
@ -38,3 +38,11 @@ export interface AmountsOutMaxFee {
|
||||
swapMarketFee: string
|
||||
maxPrice?: string
|
||||
}
|
||||
|
||||
export interface PoolPriceAndFees {
|
||||
tokenAmount: string
|
||||
liquidityProviderSwapFeeAmount: string
|
||||
oceanFeeAmount: string
|
||||
publishMarketSwapFeeAmount: string
|
||||
consumeMarketSwapFeeAmount: string
|
||||
}
|
||||
|
@ -19,7 +19,8 @@ import {
|
||||
FreCreationParams,
|
||||
Erc20CreateParams,
|
||||
PoolCreationParams,
|
||||
DispenserCreationParams
|
||||
DispenserCreationParams,
|
||||
ConsumeMarketFee
|
||||
} from '../@types/index.js'
|
||||
|
||||
interface Template {
|
||||
@ -31,7 +32,8 @@ export interface TokenOrder {
|
||||
tokenAddress: string
|
||||
consumer: string
|
||||
serviceIndex: number
|
||||
_providerFees: ProviderFees
|
||||
_providerFee: ProviderFees
|
||||
_consumeMarketFee: ConsumeMarketFee
|
||||
}
|
||||
|
||||
export interface NftCreateData {
|
||||
@ -91,6 +93,7 @@ export class NftFactory {
|
||||
nftData.symbol,
|
||||
nftData.templateIndex,
|
||||
addressZERO,
|
||||
addressZERO,
|
||||
nftData.tokenURI
|
||||
)
|
||||
.estimateGas({ from: address }, (err, estGas) => (err ? gasLimitDefault : estGas))
|
||||
@ -133,6 +136,7 @@ export class NftFactory {
|
||||
nftData.symbol,
|
||||
nftData.templateIndex,
|
||||
addressZERO,
|
||||
addressZERO,
|
||||
nftData.tokenURI
|
||||
)
|
||||
.send({
|
||||
|
@ -17,7 +17,8 @@ import {
|
||||
CurrentFees,
|
||||
TokenInOutMarket,
|
||||
AmountsInMaxFee,
|
||||
AmountsOutMaxFee
|
||||
AmountsOutMaxFee,
|
||||
PoolPriceAndFees
|
||||
} from '../../@types'
|
||||
import { Config } from '../../models'
|
||||
const MaxUint256 =
|
||||
@ -1415,7 +1416,7 @@ export class Pool {
|
||||
tokenOut: string,
|
||||
tokenAmountOut: string,
|
||||
swapMarketFee: string
|
||||
): Promise<string> {
|
||||
): Promise<PoolPriceAndFees> {
|
||||
const pool = setContractDefaults(
|
||||
new this.web3.eth.Contract(this.poolAbi, poolAddress),
|
||||
this.config
|
||||
@ -1434,7 +1435,25 @@ export class Pool {
|
||||
this.web3.utils.toWei(swapMarketFee)
|
||||
)
|
||||
.call()
|
||||
amount = await unitsToAmount(this.web3, tokenIn, result)
|
||||
amount = {
|
||||
tokenAmount: await unitsToAmount(this.web3, tokenOut, result.tokenAmountIn),
|
||||
liquidityProviderSwapFeeAmount: await unitsToAmount(
|
||||
this.web3,
|
||||
tokenIn,
|
||||
result.lpFeeAmount
|
||||
),
|
||||
oceanFeeAmount: await unitsToAmount(this.web3, tokenIn, result.oceanFeeAmount),
|
||||
publishMarketSwapFeeAmount: await unitsToAmount(
|
||||
this.web3,
|
||||
tokenIn,
|
||||
result.publishMarketSwapFeeAmount
|
||||
),
|
||||
consumeMarketSwapFeeAmount: await unitsToAmount(
|
||||
this.web3,
|
||||
tokenIn,
|
||||
result.consumeMarketSwapFeeAmount
|
||||
)
|
||||
}
|
||||
} catch (e) {
|
||||
LoggerInstance.error(`ERROR: Failed to calcInGivenOut ${e.message}`)
|
||||
}
|
||||
@ -1455,7 +1474,7 @@ export class Pool {
|
||||
tokenOut: string,
|
||||
tokenAmountIn: string,
|
||||
swapMarketFee: string
|
||||
): Promise<string> {
|
||||
): Promise<PoolPriceAndFees> {
|
||||
const pool = setContractDefaults(
|
||||
new this.web3.eth.Contract(this.poolAbi, poolAddress),
|
||||
this.config
|
||||
@ -1475,7 +1494,25 @@ export class Pool {
|
||||
)
|
||||
.call()
|
||||
|
||||
amount = await unitsToAmount(this.web3, tokenOut, result)
|
||||
amount = {
|
||||
tokenAmount: await unitsToAmount(this.web3, tokenOut, result.tokenAmountOut),
|
||||
liquidityProviderSwapFeeAmount: await unitsToAmount(
|
||||
this.web3,
|
||||
tokenIn,
|
||||
result.lpFeeAmount
|
||||
),
|
||||
oceanFeeAmount: await unitsToAmount(this.web3, tokenIn, result.oceanFeeAmount),
|
||||
publishMarketSwapFeeAmount: await unitsToAmount(
|
||||
this.web3,
|
||||
tokenIn,
|
||||
result.publishMarketSwapFeeAmount
|
||||
),
|
||||
consumeMarketSwapFeeAmount: await unitsToAmount(
|
||||
this.web3,
|
||||
tokenIn,
|
||||
result.consumeMarketSwapFeeAmount
|
||||
)
|
||||
}
|
||||
} catch (e) {
|
||||
LoggerInstance.error(`ERROR: Failed to calcOutGivenIn ${e.message}`)
|
||||
}
|
||||
|
@ -12,7 +12,12 @@ import {
|
||||
configHelperNetworks,
|
||||
getFreOrderParams
|
||||
} from '../utils'
|
||||
import { FreOrderParams, FreCreationParams, ProviderFees } from '../@types'
|
||||
import {
|
||||
ConsumeMarketFee,
|
||||
FreOrderParams,
|
||||
FreCreationParams,
|
||||
ProviderFees
|
||||
} from '../@types'
|
||||
import { Nft } from './NFT'
|
||||
import { Config } from '../models/index.js'
|
||||
|
||||
@ -27,7 +32,8 @@ interface Roles {
|
||||
export interface OrderParams {
|
||||
consumer: string
|
||||
serviceIndex: number
|
||||
_providerFees: ProviderFees
|
||||
_providerFee: ProviderFees
|
||||
_consumeMarketFee: ConsumeMarketFee
|
||||
}
|
||||
|
||||
export interface DispenserParams {
|
||||
@ -913,6 +919,7 @@ export class Datatoken {
|
||||
* @param {String} consumer Consumer Address
|
||||
* @param {Number} serviceIndex Service index in the metadata
|
||||
* @param {providerFees} providerFees provider fees
|
||||
* @param {consumeMarketFee} ConsumeMarketFee consume market fees
|
||||
* @param {Contract} contractInstance optional contract instance
|
||||
* @return {Promise<any>}
|
||||
*/
|
||||
@ -922,6 +929,7 @@ export class Datatoken {
|
||||
consumer: string,
|
||||
serviceIndex: number,
|
||||
providerFees: ProviderFees,
|
||||
consumeMarketFee?: ConsumeMarketFee,
|
||||
contractInstance?: Contract
|
||||
): Promise<any> {
|
||||
const dtContract =
|
||||
@ -936,7 +944,7 @@ export class Datatoken {
|
||||
let estGas
|
||||
try {
|
||||
estGas = await dtContract.methods
|
||||
.startOrder(consumer, serviceIndex, providerFees)
|
||||
.startOrder(consumer, serviceIndex, providerFees, consumeMarketFee)
|
||||
.estimateGas({ from: address }, (err, estGas) => (err ? gasLimitDefault : estGas))
|
||||
} catch (e) {
|
||||
estGas = gasLimitDefault
|
||||
@ -950,6 +958,7 @@ export class Datatoken {
|
||||
* @param {String} consumer Consumer Address
|
||||
* @param {Number} serviceIndex Service index in the metadata
|
||||
* @param {providerFees} providerFees provider fees
|
||||
* @param {consumeMarketFee} ConsumeMarketFee consume market fees
|
||||
* @return {Promise<TransactionReceipt>} string
|
||||
*/
|
||||
public async startOrder(
|
||||
@ -957,12 +966,20 @@ export class Datatoken {
|
||||
address: string,
|
||||
consumer: string,
|
||||
serviceIndex: number,
|
||||
providerFees: ProviderFees
|
||||
providerFees: ProviderFees,
|
||||
consumeMarketFee?: ConsumeMarketFee
|
||||
): Promise<TransactionReceipt> {
|
||||
const dtContract = setContractDefaults(
|
||||
new this.web3.eth.Contract(this.datatokensAbi, dtAddress),
|
||||
this.config
|
||||
)
|
||||
if (!consumeMarketFee) {
|
||||
consumeMarketFee = {
|
||||
consumeMarketFeeAddress: '0x0000000000000000000000000000000000000000',
|
||||
consumeMarketFeeToken: '0x0000000000000000000000000000000000000000',
|
||||
consumeMarketFeeAmount: '0'
|
||||
}
|
||||
}
|
||||
try {
|
||||
const estGas = await this.estGasStartOrder(
|
||||
dtAddress,
|
||||
@ -970,11 +987,12 @@ export class Datatoken {
|
||||
consumer,
|
||||
serviceIndex,
|
||||
providerFees,
|
||||
consumeMarketFee,
|
||||
dtContract
|
||||
)
|
||||
|
||||
const trxReceipt = await dtContract.methods
|
||||
.startOrder(consumer, serviceIndex, providerFees)
|
||||
.startOrder(consumer, serviceIndex, providerFees, consumeMarketFee)
|
||||
.send({
|
||||
from: address,
|
||||
gas: estGas + 1,
|
||||
|
@ -39,8 +39,8 @@ export const configHelperNetworks: Config[] = [
|
||||
chainId: 3,
|
||||
network: 'ropsten',
|
||||
nodeUri: 'https://ropsten.infura.io/v3',
|
||||
providerUri: 'https://provider.ropsten.oceanprotocol.com',
|
||||
subgraphUri: 'https://subgraph.ropsten.oceanprotocol.com',
|
||||
providerUri: 'https://providerv4.ropsten.oceanprotocol.com',
|
||||
subgraphUri: 'https://subgraphv4.ropsten.oceanprotocol.com',
|
||||
explorerUri: 'https://ropsten.etherscan.io',
|
||||
startBlock: 9227563
|
||||
},
|
||||
@ -82,10 +82,10 @@ export const configHelperNetworks: Config[] = [
|
||||
{
|
||||
...configHelperNetworksBase,
|
||||
chainId: 1287,
|
||||
network: 'moonbeamalpha',
|
||||
network: 'moonbase',
|
||||
nodeUri: 'https://rpc.testnet.moonbeam.network',
|
||||
providerUri: 'https://provider.moonbeamalpha.oceanprotocol.com',
|
||||
subgraphUri: 'https://subgraph.moonbeamalpha.oceanprotocol.com',
|
||||
providerUri: 'https://providerv4.moonbase.oceanprotocol.com',
|
||||
subgraphUri: 'https://subgraphv4.moonbase.oceanprotocol.com',
|
||||
explorerUri: 'https://moonbase-blockscout.testnet.moonbeam.network/',
|
||||
startBlock: 90707
|
||||
},
|
||||
@ -113,8 +113,8 @@ export const configHelperNetworks: Config[] = [
|
||||
chainId: 80001,
|
||||
network: 'mumbai',
|
||||
nodeUri: 'https://polygon-mumbai.infura.io/v3',
|
||||
providerUri: 'https://provider.mumbai.oceanprotocol.com',
|
||||
subgraphUri: 'https://subgraph.mumbai.oceanprotocol.com',
|
||||
providerUri: 'https://providerv4.mumbai.oceanprotocol.com',
|
||||
subgraphUri: 'https://subgraphv4.mumbai.oceanprotocol.com',
|
||||
explorerUri: 'https://mumbai.polygonscan.com'
|
||||
},
|
||||
{
|
||||
|
@ -11,6 +11,7 @@ import { SHA256 } from 'crypto-js'
|
||||
import { homedir } from 'os'
|
||||
import fs from 'fs'
|
||||
import { ProviderFees, Erc20CreateParams } from '../../src/@types'
|
||||
import console from 'console'
|
||||
|
||||
const data = JSON.parse(
|
||||
fs.readFileSync(
|
||||
@ -240,11 +241,12 @@ describe('Simple compute tests', async () => {
|
||||
const computeEnvs = await ProviderInstance.getComputeEnvironments(providerUrl)
|
||||
assert(computeEnvs, 'No Compute environments found')
|
||||
// we choose the first env
|
||||
console.log(computeEnvs)
|
||||
const computeEnv = computeEnvs[0].id
|
||||
const computeConsumerAddress = computeEnvs[0].consumerAddress
|
||||
// let's have 60 seconds of compute access
|
||||
// let's have 10 minutesof compute access
|
||||
const mytime = new Date()
|
||||
mytime.setMinutes(mytime.getMinutes() + 1)
|
||||
mytime.setMinutes(mytime.getMinutes() + 19)
|
||||
const computeValidUntil = Math.floor(mytime.getTime() / 1000)
|
||||
// initialize provider orders for algo
|
||||
const initializeDataAlgo = await ProviderInstance.initialize(
|
||||
@ -295,6 +297,7 @@ describe('Simple compute tests', async () => {
|
||||
computeEnv,
|
||||
computeValidUntil
|
||||
)
|
||||
console.log(initializeData)
|
||||
const providerDatasetFees: ProviderFees = {
|
||||
providerFeeAddress: initializeData.providerFee.providerFeeAddress,
|
||||
providerFeeToken: initializeData.providerFee.providerFeeToken,
|
||||
|
@ -398,18 +398,25 @@ describe('Nft Factory test', () => {
|
||||
providerData: web3.utils.toHex(web3.utils.asciiToHex(providerData)),
|
||||
validUntil: providerValidUntil
|
||||
}
|
||||
const consumeMarketFee = {
|
||||
consumeMarketFeeAddress: '0x0000000000000000000000000000000000000000',
|
||||
consumeMarketFeeToken: '0x0000000000000000000000000000000000000000',
|
||||
consumeMarketFeeAmount: '0'
|
||||
}
|
||||
const orders: TokenOrder[] = [
|
||||
{
|
||||
tokenAddress: dtAddress,
|
||||
consumer: consumer,
|
||||
serviceIndex: serviceIndex,
|
||||
_providerFees: providerFees
|
||||
_providerFee: providerFees,
|
||||
_consumeMarketFee: consumeMarketFee
|
||||
},
|
||||
{
|
||||
tokenAddress: dtAddress2,
|
||||
consumer: consumer,
|
||||
serviceIndex: serviceIndex,
|
||||
_providerFees: providerFees
|
||||
_providerFee: providerFees,
|
||||
_consumeMarketFee: consumeMarketFee
|
||||
}
|
||||
]
|
||||
await nftFactory.startMultipleTokenOrder(user2, orders)
|
||||
|
@ -417,13 +417,14 @@ describe('Pool unit test', () => {
|
||||
const maxBTPIn = '0.5'
|
||||
const exactDAIOut = '1'
|
||||
|
||||
const amountIn = await pool.getAmountInExactOut(
|
||||
const result = await pool.getAmountInExactOut(
|
||||
poolAddress,
|
||||
erc20Token,
|
||||
contracts.daiAddress,
|
||||
exactDAIOut,
|
||||
'0.1'
|
||||
)
|
||||
const amountIn = result.tokenAmount
|
||||
|
||||
assert(amountIn != null)
|
||||
|
||||
@ -443,13 +444,14 @@ describe('Pool unit test', () => {
|
||||
it('#getAmountOutExactIn- should get the amount out for exact In', async () => {
|
||||
const exactDTIn = '1'
|
||||
|
||||
const amountOut = await pool.getAmountOutExactIn(
|
||||
const result = await pool.getAmountOutExactIn(
|
||||
poolAddress,
|
||||
erc20Token,
|
||||
contracts.daiAddress,
|
||||
exactDTIn,
|
||||
'0.1'
|
||||
)
|
||||
const amountOut = result.tokenAmount
|
||||
|
||||
assert(amountOut != null)
|
||||
|
||||
@ -919,14 +921,14 @@ describe('Pool unit test', () => {
|
||||
const maxBTPIn = '0.5'
|
||||
const exactUSDCOut = '1'
|
||||
|
||||
const amountIn = await pool.getAmountInExactOut(
|
||||
const result = await pool.getAmountInExactOut(
|
||||
poolAddress,
|
||||
erc20Token,
|
||||
contracts.usdcAddress,
|
||||
exactUSDCOut,
|
||||
'0.1'
|
||||
)
|
||||
|
||||
const amountIn = result.tokenAmount
|
||||
assert(amountIn != null)
|
||||
|
||||
const spotPrice = await pool.getSpotPrice(
|
||||
@ -942,13 +944,14 @@ describe('Pool unit test', () => {
|
||||
it('#getAmountOutExactIn- should get the amount out for exact In', async () => {
|
||||
const exactDTIn = '1'
|
||||
|
||||
const amountOut = await pool.getAmountOutExactIn(
|
||||
const result = await pool.getAmountOutExactIn(
|
||||
poolAddress,
|
||||
erc20Token,
|
||||
contracts.usdcAddress,
|
||||
exactDTIn,
|
||||
'0.1'
|
||||
)
|
||||
const amountOut = result.tokenAmount
|
||||
|
||||
assert(amountOut != null)
|
||||
|
||||
|
@ -408,10 +408,16 @@ describe('Datatoken', () => {
|
||||
providerData: web3.utils.toHex(web3.utils.asciiToHex(providerData)),
|
||||
validUntil: providerValidUntil
|
||||
}
|
||||
const consumeMarketFee = {
|
||||
consumeMarketFeeAddress: '0x0000000000000000000000000000000000000000',
|
||||
consumeMarketFeeToken: '0x0000000000000000000000000000000000000000',
|
||||
consumeMarketFeeAmount: '0'
|
||||
}
|
||||
const order: OrderParams = {
|
||||
consumer: user1,
|
||||
serviceIndex: 1,
|
||||
_providerFees: providerFees
|
||||
_providerFee: providerFees,
|
||||
_consumeMarketFee: consumeMarketFee
|
||||
}
|
||||
const buyFromDispenseTx = await datatoken.buyFromDispenserAndOrder(
|
||||
datatokenAddress,
|
||||
@ -444,10 +450,16 @@ describe('Datatoken', () => {
|
||||
providerData: web3.utils.toHex(web3.utils.asciiToHex(providerData)),
|
||||
validUntil: providerValidUntil
|
||||
}
|
||||
const consumeMarketFee = {
|
||||
consumeMarketFeeAddress: '0x0000000000000000000000000000000000000000',
|
||||
consumeMarketFeeToken: '0x0000000000000000000000000000000000000000',
|
||||
consumeMarketFeeAmount: '0'
|
||||
}
|
||||
const order: OrderParams = {
|
||||
consumer: user1,
|
||||
serviceIndex: 1,
|
||||
_providerFees: providerFees
|
||||
_providerFee: providerFees,
|
||||
_consumeMarketFee: consumeMarketFee
|
||||
}
|
||||
|
||||
const fre: FreOrderParams = {
|
||||
|
Loading…
x
Reference in New Issue
Block a user