1
0
mirror of https://github.com/oceanprotocol/market.git synced 2024-12-02 05:57:29 +01:00

fixed get algo list

This commit is contained in:
Bogdan Fazakas 2022-02-28 14:56:13 +02:00
parent 0085174e8d
commit 27665c277d
3 changed files with 404 additions and 446 deletions

View File

@ -1,20 +1,12 @@
// import {
// ServiceComputePrivacy,
// publisherTrustedAlgorithm as PublisherTrustedAlgorithm,
// Service,
// LoggerInstance,
// Provider,
// Config,
// Ocean,
// Account
// } from '@oceanprotocol/lib'
// import { ComputeJob } from '@oceanprotocol/lib/dist/node/ocean/interfaces/Compute'
import {
Asset,
ServiceComputeOptions,
PublisherTrustedAlgorithm,
getHash,
LoggerInstance
LoggerInstance,
ComputeAlgorithm,
DDO,
Service
} from '@oceanprotocol/lib'
import { CancelToken } from 'axios'
import { gql } from 'urql'
@ -29,6 +21,7 @@ import { getServiceById, getServiceByName } from './ddo'
import { getOceanConfig } from './ocean'
import { SortTermOptions } from 'src/@types/aquarius/SearchQuery'
import { AssetSelectionAsset } from '@shared/FormFields/AssetSelection'
import { transformAssetToAssetSelection } from './assetConvertor'
const getComputeOrders = gql`
query ComputeOrders($user: String!) {
@ -121,7 +114,7 @@ export async function isOrderable(
}
}
function getQuerryString(
export function getQuerryString(
trustedAlgorithmList: PublisherTrustedAlgorithm[],
chainId?: number
): SearchQuery {
@ -132,11 +125,12 @@ function getQuerryString(
sort: { sortBy: SortTermOptions.Created },
filters: [
getFilterTerm('metadata.type', 'algorithm'),
getFilterTerm('id', algorithmDidList)
getFilterTerm('_id', algorithmDidList)
]
} as BaseQueryParams
const query = generateBaseQuery(baseParams)
console.log('querry', query)
return query
}
@ -145,12 +139,14 @@ export async function getAlgorithmsForAsset(
token: CancelToken
): Promise<Asset[]> {
const computeService: Service = getServiceByName(asset, 'compute')
console.log('computeService: ', computeService)
let algorithms: Asset[]
if (
!computeService.compute ||
!computeService.compute.publisherTrustedAlgorithms ||
computeService.compute.publisherTrustedAlgorithms.length === 0
) {
console.log('computeService: []')
algorithms = []
} else {
const gueryResults = await queryMetadata(
@ -160,6 +156,7 @@ export async function getAlgorithmsForAsset(
),
token
)
console.log('gueryResults: ', gueryResults)
algorithms = gueryResults?.results
}
return algorithms
@ -167,8 +164,7 @@ export async function getAlgorithmsForAsset(
export async function getAlgorithmAssetSelectionList(
asset: Asset,
algorithms: Asset[],
token: CancelToken
algorithms: Asset[]
): Promise<AssetSelectionAsset[]> {
const computeService: Service = getServiceByName(asset, 'compute')
let algorithmSelectionList: AssetSelectionAsset[]
@ -179,11 +175,10 @@ export async function getAlgorithmAssetSelectionList(
) {
algorithmSelectionList = []
} else {
algorithmSelectionList = await transformDDOToAssetSelection(
algorithmSelectionList = await transformAssetToAssetSelection(
computeService?.serviceEndpoint,
algorithms,
[],
token
[]
)
}
return algorithmSelectionList

View File

@ -10,7 +10,10 @@ export default function Blockies({
className?: string
}): ReactElement {
if (!accountId) return null
const blockies = toDataUrl(accountId)
// TODO: just put this back once finished
// const blockies = toDataUrl(accountId)
const blockies = 'randomstring12345'
return (
<img

View File

@ -41,7 +41,8 @@ import { getServiceByName, secondsToString } from '@utils/ddo'
import {
isOrderable,
getAlgorithmAssetSelectionList,
getAlgorithmsForAsset
getAlgorithmsForAsset,
getQuerryString
} from '@utils/compute'
import AssetSelection, {
AssetSelectionAsset
@ -143,28 +144,9 @@ export default function Compute({
setHasAlgoAssetDatatoken(Number(AssetDtBalance) >= 1)
}
function getQuerryString(
trustedAlgorithmList: PublisherTrustedAlgorithm[],
chainId?: number
): SearchQuery {
const algorithmDidList = trustedAlgorithmList.map((x) => x.did)
const baseParams = {
chainIds: [chainId],
sort: { sortBy: SortTermOptions.Created },
filters: [
getFilterTerm('service.attributes.main.type', 'algorithm'),
getFilterTerm('id', algorithmDidList)
]
} as BaseQueryParams
const query = generateBaseQuery(baseParams)
return query
}
async function getAlgorithmList(): Promise<AssetSelectionAsset[]> {
const source = axios.CancelToken.source()
const computeService = ddo.services[0]
const computeService = asset.services[0]
let algorithmSelectionList: AssetSelectionAsset[]
if (
!computeService.compute ||
@ -176,7 +158,7 @@ export default function Compute({
const gueryResults = await queryMetadata(
getQuerryString(
computeService.compute.publisherTrustedAlgorithms,
ddo.chainId
asset.chainId
),
source.token
)
@ -220,14 +202,13 @@ export default function Compute({
if (!asset) return
getAlgorithmsForAsset(asset, newCancelToken()).then((algorithmsAssets) => {
console.log('getAlgorithmsForAsset', algorithmsAssets)
setDdoAlgorithmList(algorithmsAssets)
getAlgorithmAssetSelectionList(
asset,
algorithmsAssets,
newCancelToken()
).then((algorithmSelectionList) => {
setAlgorithmList(algorithmSelectionList)
})
getAlgorithmAssetSelectionList(asset, algorithmsAssets).then(
(algorithmSelectionList) => {
setAlgorithmList(algorithmSelectionList)
}
)
})
}, [asset])
@ -271,403 +252,382 @@ export default function Compute({
async function startJob(algorithmId: string): Promise<string> {
try {
setIsJobStarting(true)
setIsPublished(false) // would be nice to rename this
setError(undefined)
const computeService = getServiceByName(asset, 'compute')
const serviceAlgo = getServiceByName(selectedAlgorithmAsset, 'access')
? getServiceByName(selectedAlgorithmAsset, 'access')
: getServiceByName(selectedAlgorithmAsset, 'compute')
const computeAlgorithm: ComputeAlgorithm = {
documentId: selectedAlgorithmAsset.id,
serviceId: selectedAlgorithmAsset.services[0].id
}
const allowed = await isOrderable(
asset,
computeService.id,
computeAlgorithm,
selectedAlgorithmAsset
)
LoggerInstance.log('[compute] Is data set orderable?', allowed)
if (!allowed) {
setError(
'Data set is not orderable in combination with selected algorithm.'
)
LoggerInstance.error(
'[compute] Error starting compute job. Dataset is not orderable in combination with selected algorithm.'
)
return
}
let assetOrderId = hasPreviousDatasetOrder ? previousDatasetOrderId : ''
if (!hasPreviousDatasetOrder) {
// going to move/replace part of this logic when the use consume hook will be ready
const initializeData = await ProviderInstance.initialize(
asset.id,
asset.services[0].id,
0,
accountId,
asset.services[0].serviceEndpoint // to check
)
const providerFees: ProviderFees = {
providerFeeAddress: initializeData.providerFee.providerFeeAddress,
providerFeeToken: initializeData.providerFee.providerFeeToken,
providerFeeAmount: initializeData.providerFee.providerFeeAmount,
v: initializeData.providerFee.v,
r: initializeData.providerFee.r,
s: initializeData.providerFee.s,
providerData: initializeData.providerFee.providerData,
validUntil: initializeData.providerFee.validUntil
}
if (!hasDatatoken) {
let tx: TransactionReceipt
switch (accessDetails?.type) {
case 'dynamic': {
const oceanAmmount = new Decimal(accessDetails.price)
.times(1.05)
.toString()
const maxPrice = new Decimal(accessDetails.price)
.times(2)
.toString()
const poolInstance = new Pool(web3)
if (
new Decimal('1').greaterThan(
await poolInstance.getReserve(
accessDetails.addressOrId,
accessDetails.datatoken.address
)
)
) {
LoggerInstance.error(
'ERROR: Buy quantity exceeds quantity allowed'
)
}
const calcInGivenOut = await poolInstance.getAmountInExactOut(
accessDetails.addressOrId,
accessDetails.baseToken.address,
accessDetails.datatoken.address,
'1',
'0.1'
)
if (new Decimal(calcInGivenOut).greaterThan(oceanAmmount)) {
this.logger.error('ERROR: Not enough Ocean Tokens')
return null
}
const approvetx = await approve(
web3,
accountId,
accessDetails.baseToken.address,
accountId,
'1'
)
if (!approvetx) {
LoggerInstance.error(
'ERROR: Failed to call approve OCEAN token'
)
}
const tokenInOutMarket: TokenInOutMarket = {
tokenIn: accessDetails.baseToken.address,
tokenOut: accessDetails.datatoken.address,
marketFeeAddress: appConfig.marketFeeAddress
}
const amountsInOutMaxFee: AmountsOutMaxFee = {
maxAmountIn: oceanAmmount,
tokenAmountOut: '1',
swapMarketFee: '0.1'
}
const tx = await poolInstance.swapExactAmountOut(
accountId,
accessDetails.addressOrId,
tokenInOutMarket,
amountsInOutMaxFee
)
break
}
case 'fixed': {
const datatokenInstance = new Datatoken(web3)
const order: OrderParams = {
consumer: accountId,
serviceIndex: 1,
_providerFees: providerFees
}
const fre: FreOrderParams = {
exchangeContract: accessDetails.addressOrId,
exchangeId:
'0x7ac824fef114255e5e3521a161ef692ec32003916fb6f3fe985cb74790d053ca',
maxBaseTokenAmount: '1',
swapMarketFee: web3.utils.toWei('0.1'),
marketFeeAddress: appConfig.marketFeeAddress
}
tx = await datatokenInstance.buyFromFreAndOrder(
asset.datatokens[0].address,
accountId,
order,
fre
)
assetOrderId = tx.transactionHash
break
}
case 'free': {
const datatokenInstance = new Datatoken(web3)
const order: OrderParams = {
consumer: accountId,
serviceIndex: 0,
_providerFees: providerFees
}
const fre: FreOrderParams = {
exchangeContract: accessDetails.addressOrId,
exchangeId:
'0x7ac824fef114255e5e3521a161ef692ec32003916fb6f3fe985cb74790d053ca',
maxBaseTokenAmount: '1',
swapMarketFee: web3.utils.toWei('0.1'),
marketFeeAddress: appConfig.marketFeeAddress
}
tx = await datatokenInstance.buyFromDispenserAndOrder(
asset.datatokens[0].address,
accountId,
order,
accessDetails.addressOrId
)
assetOrderId = tx.transactionHash
if (!tx) {
setError('Error buying datatoken.')
LoggerInstance.error(
'[compute] Error buying datatoken for data set ',
asset.id
)
return
}
break
}
}
} else {
const datatokenInstance = new Datatoken(web3)
const tx = await datatokenInstance.startOrder(
asset.datatokens[0].address,
accountId,
initializeData.computeAddress,
0,
providerFees
)
assetOrderId = tx.transactionHash
}
}
let algorithmAssetOrderId = hasPreviousAlgorithmOrder
? previousAlgorithmOrderId
: ''
// add method for this logic
if (!hasPreviousAlgorithmOrder) {
// going to move replace part of this logic when the use consume hook will be ready
const initializeData = await ProviderInstance.initialize(
selectedAlgorithmAsset.id,
selectedAlgorithmAsset.services[0].id,
0,
accountId,
selectedAlgorithmAsset.services[0].serviceEndpoint // to check
)
const providerFees: ProviderFees = {
providerFeeAddress: initializeData.providerFee.providerFeeAddress,
providerFeeToken: initializeData.providerFee.providerFeeToken,
providerFeeAmount: initializeData.providerFee.providerFeeAmount,
v: initializeData.providerFee.v,
r: initializeData.providerFee.r,
s: initializeData.providerFee.s,
providerData: initializeData.providerFee.providerData,
validUntil: initializeData.providerFee.validUntil
}
if (!hasAlgoAssetDatatoken) {
let tx: TransactionReceipt
switch (algorithmConsumeDetails?.type) {
case 'dynamic': {
const oceanAmmount = new Decimal(algorithmConsumeDetails.price)
.times(1.05)
.toString()
const maxPrice = new Decimal(algorithmConsumeDetails.price)
.times(2)
.toString()
const poolInstance = new Pool(web3)
if (
new Decimal('1').greaterThan(
await poolInstance.getReserve(
algorithmConsumeDetails.addressOrId,
algorithmConsumeDetails.datatoken.address
)
)
) {
LoggerInstance.error(
'ERROR: Buy quantity exceeds quantity allowed'
)
}
const calcInGivenOut = await poolInstance.getAmountInExactOut(
algorithmConsumeDetails.addressOrId,
algorithmConsumeDetails.baseToken.address,
algorithmConsumeDetails.datatoken.address,
'1',
'0.1'
)
if (new Decimal(calcInGivenOut).greaterThan(oceanAmmount)) {
this.logger.error('ERROR: Not enough Ocean Tokens')
return null
}
const approvetx = await approve(
web3,
accountId,
algorithmConsumeDetails.baseToken.address,
accountId,
'1'
)
if (!approvetx) {
LoggerInstance.error(
'ERROR: Failed to call approve OCEAN token'
)
}
const tokenInOutMarket: TokenInOutMarket = {
tokenIn: algorithmConsumeDetails.baseToken.address,
tokenOut: algorithmConsumeDetails.datatoken.address,
marketFeeAddress: appConfig.marketFeeAddress
}
const amountsInOutMaxFee: AmountsOutMaxFee = {
maxAmountIn: oceanAmmount,
tokenAmountOut: '1',
swapMarketFee: '0.1'
}
const tx = await poolInstance.swapExactAmountOut(
accountId,
algorithmConsumeDetails.addressOrId,
tokenInOutMarket,
amountsInOutMaxFee
)
break
}
case 'fixed': {
const datatokenInstance = new Datatoken(web3)
const order: OrderParams = {
consumer: accountId,
serviceIndex: 1,
_providerFees: providerFees
}
const fre: FreOrderParams = {
exchangeContract: algorithmConsumeDetails.addressOrId,
exchangeId:
'0x7ac824fef114255e5e3521a161ef692ec32003916fb6f3fe985cb74790d053ca',
maxBaseTokenAmount: '1',
swapMarketFee: web3.utils.toWei('0.1'), // to update
marketFeeAddress: appConfig.marketFeeAddress
}
tx = await datatokenInstance.buyFromFreAndOrder(
selectedAlgorithmAsset.datatokens[0].address,
accountId,
order,
fre
)
algorithmAssetOrderId = tx.transactionHash
break
}
case 'free': {
const datatokenInstance = new Datatoken(web3)
const order: OrderParams = {
consumer: accountId,
serviceIndex: 1,
_providerFees: providerFees
}
const fre: FreOrderParams = {
exchangeContract: algorithmConsumeDetails.addressOrId,
exchangeId:
'0x7ac824fef114255e5e3521a161ef692ec32003916fb6f3fe985cb74790d053ca',
maxBaseTokenAmount: '1',
swapMarketFee: web3.utils.toWei('0.1'), // to update
marketFeeAddress: appConfig.marketFeeAddress
}
tx = await datatokenInstance.buyFromDispenserAndOrder(
selectedAlgorithmAsset.datatokens[0].address,
accountId,
order,
algorithmConsumeDetails.addressOrId
)
algorithmAssetOrderId = tx.transactionHash
break
}
}
} else {
const datatokenInstance = new Datatoken(web3)
const tx = await datatokenInstance.startOrder(
selectedAlgorithmAsset.datatokens[0].address,
accountId,
initializeData.computeAddress,
0,
providerFees
)
algorithmAssetOrderId = tx.transactionHash
}
}
LoggerInstance.log(
`[compute] Got ${
hasPreviousDatasetOrder ? 'existing' : 'new'
} order ID for dataset: `,
assetOrderId
)
LoggerInstance.log(
`[compute] Got ${
hasPreviousAlgorithmOrder ? 'existing' : 'new'
} order ID for algorithm: `,
algorithmAssetOrderId
)
if (!assetOrderId || !algorithmAssetOrderId) {
setError('Error ordering assets.')
return
}
computeAlgorithm.transferTxId = algorithmAssetOrderId
LoggerInstance.log('[compute] Starting compute job.')
const computeAsset: ComputeAsset = {
documentId: asset.id,
serviceId: asset.services[0].id,
transferTxId: assetOrderId
}
computeAlgorithm.transferTxId = algorithmAssetOrderId
const output: ComputeOutput = {
publishAlgorithmLog: true,
publishOutput: true
}
const response = await ProviderInstance.computeStart(
asset.services[0].serviceEndpoint,
web3,
accountId,
'env1',
computeAsset,
computeAlgorithm,
newAbortController(),
null,
output
)
if (!response) {
setError('Error starting compute job.')
return
}
LoggerInstance.log('[compute] Starting compute job response: ', response)
await checkPreviousOrders(selectedAlgorithmAsset)
await checkPreviousOrders(asset)
setIsPublished(true)
// setIsJobStarting(true)
// setIsPublished(false) // would be nice to rename this
// setError(undefined)
// const computeService = getServiceByName(asset, 'compute')
// const serviceAlgo = getServiceByName(selectedAlgorithmAsset, 'access')
// ? getServiceByName(selectedAlgorithmAsset, 'access')
// : getServiceByName(selectedAlgorithmAsset, 'compute')
// const computeAlgorithm: ComputeAlgorithm = {
// documentId: selectedAlgorithmAsset.id,
// serviceId: selectedAlgorithmAsset.services[0].id
// }
// const allowed = await isOrderable(
// asset,
// computeService.id,
// computeAlgorithm,
// selectedAlgorithmAsset
// )
// LoggerInstance.log('[compute] Is data set orderable?', allowed)
// if (!allowed) {
// setError(
// 'Data set is not orderable in combination with selected algorithm.'
// )
// LoggerInstance.error(
// '[compute] Error starting compute job. Dataset is not orderable in combination with selected algorithm.'
// )
// return
// }
// let assetOrderId = hasPreviousDatasetOrder ? previousDatasetOrderId : ''
// if (!hasPreviousDatasetOrder) {
// // going to move/replace part of this logic when the use consume hook will be ready
// const initializeData = await ProviderInstance.initialize(
// asset.id,
// asset.services[0].id,
// 0,
// accountId,
// asset.services[0].serviceEndpoint // to check
// )
// const providerFees: ProviderFees = {
// providerFeeAddress: initializeData.providerFee.providerFeeAddress,
// providerFeeToken: initializeData.providerFee.providerFeeToken,
// providerFeeAmount: initializeData.providerFee.providerFeeAmount,
// v: initializeData.providerFee.v,
// r: initializeData.providerFee.r,
// s: initializeData.providerFee.s,
// providerData: initializeData.providerFee.providerData,
// validUntil: initializeData.providerFee.validUntil
// }
// if (!hasDatatoken) {
// let tx: TransactionReceipt
// switch (accessDetails?.type) {
// case 'dynamic': {
// const oceanAmmount = new Decimal(accessDetails.price)
// .times(1.05)
// .toString()
// const maxPrice = new Decimal(accessDetails.price)
// .times(2)
// .toString()
// const poolInstance = new Pool(web3)
// if (
// new Decimal('1').greaterThan(
// await poolInstance.getReserve(
// accessDetails.addressOrId,
// accessDetails.datatoken.address
// )
// )
// ) {
// LoggerInstance.error(
// 'ERROR: Buy quantity exceeds quantity allowed'
// )
// }
// const calcInGivenOut = await poolInstance.getAmountInExactOut(
// accessDetails.addressOrId,
// accessDetails.baseToken.address,
// accessDetails.datatoken.address,
// '1',
// '0.1'
// )
// if (new Decimal(calcInGivenOut).greaterThan(oceanAmmount)) {
// this.logger.error('ERROR: Not enough Ocean Tokens')
// return null
// }
// const approvetx = await approve(
// web3,
// accountId,
// accessDetails.baseToken.address,
// accountId,
// '1'
// )
// if (!approvetx) {
// LoggerInstance.error(
// 'ERROR: Failed to call approve OCEAN token'
// )
// }
// const tokenInOutMarket: TokenInOutMarket = {
// tokenIn: accessDetails.baseToken.address,
// tokenOut: accessDetails.datatoken.address,
// marketFeeAddress: appConfig.marketFeeAddress
// }
// const amountsInOutMaxFee: AmountsOutMaxFee = {
// maxAmountIn: oceanAmmount,
// tokenAmountOut: '1',
// swapMarketFee: '0.1'
// }
// const tx = await poolInstance.swapExactAmountOut(
// accountId,
// accessDetails.addressOrId,
// tokenInOutMarket,
// amountsInOutMaxFee
// )
// break
// }
// case 'fixed': {
// const datatokenInstance = new Datatoken(web3)
// const order: OrderParams = {
// consumer: accountId,
// serviceIndex: 1,
// _providerFees: providerFees
// }
// const fre: FreOrderParams = {
// exchangeContract: accessDetails.addressOrId,
// exchangeId:
// '0x7ac824fef114255e5e3521a161ef692ec32003916fb6f3fe985cb74790d053ca',
// maxBaseTokenAmount: '1',
// swapMarketFee: web3.utils.toWei('0.1'),
// marketFeeAddress: appConfig.marketFeeAddress
// }
// tx = await datatokenInstance.buyFromFreAndOrder(
// asset.datatokens[0].address,
// accountId,
// order,
// fre
// )
// assetOrderId = tx.transactionHash
// break
// }
// case 'free': {
// const datatokenInstance = new Datatoken(web3)
// const order: OrderParams = {
// consumer: accountId,
// serviceIndex: 0,
// _providerFees: providerFees
// }
// const fre: FreOrderParams = {
// exchangeContract: accessDetails.addressOrId,
// exchangeId:
// '0x7ac824fef114255e5e3521a161ef692ec32003916fb6f3fe985cb74790d053ca',
// maxBaseTokenAmount: '1',
// swapMarketFee: web3.utils.toWei('0.1'),
// marketFeeAddress: appConfig.marketFeeAddress
// }
// tx = await datatokenInstance.buyFromDispenserAndOrder(
// asset.datatokens[0].address,
// accountId,
// order,
// accessDetails.addressOrId
// )
// assetOrderId = tx.transactionHash
// if (!tx) {
// setError('Error buying datatoken.')
// LoggerInstance.error(
// '[compute] Error buying datatoken for data set ',
// asset.id
// )
// return
// }
// break
// }
// }
// } else {
// const datatokenInstance = new Datatoken(web3)
// const tx = await datatokenInstance.startOrder(
// asset.datatokens[0].address,
// accountId,
// initializeData.computeAddress,
// 0,
// providerFees
// )
// assetOrderId = tx.transactionHash
// }
// }
// let algorithmAssetOrderId = hasPreviousAlgorithmOrder
// ? previousAlgorithmOrderId
// : ''
// // add method for this logic
// if (!hasPreviousAlgorithmOrder) {
// // going to move replace part of this logic when the use consume hook will be ready
// const initializeData = await ProviderInstance.initialize(
// selectedAlgorithmAsset.id,
// selectedAlgorithmAsset.services[0].id,
// 0,
// accountId,
// selectedAlgorithmAsset.services[0].serviceEndpoint // to check
// )
// const providerFees: ProviderFees = {
// providerFeeAddress: initializeData.providerFee.providerFeeAddress,
// providerFeeToken: initializeData.providerFee.providerFeeToken,
// providerFeeAmount: initializeData.providerFee.providerFeeAmount,
// v: initializeData.providerFee.v,
// r: initializeData.providerFee.r,
// s: initializeData.providerFee.s,
// providerData: initializeData.providerFee.providerData,
// validUntil: initializeData.providerFee.validUntil
// }
// if (!hasAlgoAssetDatatoken) {
// let tx: TransactionReceipt
// switch (algorithmConsumeDetails?.type) {
// case 'dynamic': {
// const oceanAmmount = new Decimal(algorithmConsumeDetails.price)
// .times(1.05)
// .toString()
// const maxPrice = new Decimal(algorithmConsumeDetails.price)
// .times(2)
// .toString()
// const poolInstance = new Pool(web3)
// if (
// new Decimal('1').greaterThan(
// await poolInstance.getReserve(
// algorithmConsumeDetails.addressOrId,
// algorithmConsumeDetails.datatoken.address
// )
// )
// ) {
// LoggerInstance.error(
// 'ERROR: Buy quantity exceeds quantity allowed'
// )
// }
// const calcInGivenOut = await poolInstance.getAmountInExactOut(
// algorithmConsumeDetails.addressOrId,
// algorithmConsumeDetails.baseToken.address,
// algorithmConsumeDetails.datatoken.address,
// '1',
// '0.1'
// )
// if (new Decimal(calcInGivenOut).greaterThan(oceanAmmount)) {
// this.logger.error('ERROR: Not enough Ocean Tokens')
// return null
// }
// const approvetx = await approve(
// web3,
// accountId,
// algorithmConsumeDetails.baseToken.address,
// accountId,
// '1'
// )
// if (!approvetx) {
// LoggerInstance.error(
// 'ERROR: Failed to call approve OCEAN token'
// )
// }
// const tokenInOutMarket: TokenInOutMarket = {
// tokenIn: algorithmConsumeDetails.baseToken.address,
// tokenOut: algorithmConsumeDetails.datatoken.address,
// marketFeeAddress: appConfig.marketFeeAddress
// }
// const amountsInOutMaxFee: AmountsOutMaxFee = {
// maxAmountIn: oceanAmmount,
// tokenAmountOut: '1',
// swapMarketFee: '0.1'
// }
// const tx = await poolInstance.swapExactAmountOut(
// accountId,
// algorithmConsumeDetails.addressOrId,
// tokenInOutMarket,
// amountsInOutMaxFee
// )
// break
// }
// case 'fixed': {
// const datatokenInstance = new Datatoken(web3)
// const order: OrderParams = {
// consumer: accountId,
// serviceIndex: 1,
// _providerFees: providerFees
// }
// const fre: FreOrderParams = {
// exchangeContract: algorithmConsumeDetails.addressOrId,
// exchangeId:
// '0x7ac824fef114255e5e3521a161ef692ec32003916fb6f3fe985cb74790d053ca',
// maxBaseTokenAmount: '1',
// swapMarketFee: web3.utils.toWei('0.1'), // to update
// marketFeeAddress: appConfig.marketFeeAddress
// }
// tx = await datatokenInstance.buyFromFreAndOrder(
// selectedAlgorithmAsset.datatokens[0].address,
// accountId,
// order,
// fre
// )
// algorithmAssetOrderId = tx.transactionHash
// break
// }
// case 'free': {
// const datatokenInstance = new Datatoken(web3)
// const order: OrderParams = {
// consumer: accountId,
// serviceIndex: 1,
// _providerFees: providerFees
// }
// const fre: FreOrderParams = {
// exchangeContract: algorithmConsumeDetails.addressOrId,
// exchangeId:
// '0x7ac824fef114255e5e3521a161ef692ec32003916fb6f3fe985cb74790d053ca',
// maxBaseTokenAmount: '1',
// swapMarketFee: web3.utils.toWei('0.1'), // to update
// marketFeeAddress: appConfig.marketFeeAddress
// }
// tx = await datatokenInstance.buyFromDispenserAndOrder(
// selectedAlgorithmAsset.datatokens[0].address,
// accountId,
// order,
// algorithmConsumeDetails.addressOrId
// )
// algorithmAssetOrderId = tx.transactionHash
// break
// }
// }
// } else {
// const datatokenInstance = new Datatoken(web3)
// const tx = await datatokenInstance.startOrder(
// selectedAlgorithmAsset.datatokens[0].address,
// accountId,
// initializeData.computeAddress,
// 0,
// providerFees
// )
// algorithmAssetOrderId = tx.transactionHash
// }
// }
// LoggerInstance.log(
// `[compute] Got ${
// hasPreviousDatasetOrder ? 'existing' : 'new'
// } order ID for dataset: `,
// assetOrderId
// )
// LoggerInstance.log(
// `[compute] Got ${
// hasPreviousAlgorithmOrder ? 'existing' : 'new'
// } order ID for algorithm: `,
// algorithmAssetOrderId
// )
// if (!assetOrderId || !algorithmAssetOrderId) {
// setError('Error ordering assets.')
// return
// }
// computeAlgorithm.transferTxId = algorithmAssetOrderId
// LoggerInstance.log('[compute] Starting compute job.')
// const computeAsset: ComputeAsset = {
// documentId: asset.id,
// serviceId: asset.services[0].id,
// transferTxId: assetOrderId
// }
// computeAlgorithm.transferTxId = algorithmAssetOrderId
// const output: ComputeOutput = {
// publishAlgorithmLog: true,
// publishOutput: true
// }
// const response = await ProviderInstance.computeStart(
// asset.services[0].serviceEndpoint,
// web3,
// accountId,
// 'env1',
// computeAsset,
// computeAlgorithm,
// newAbortController(),
// null,
// output
// )
// if (!response) {
// setError('Error starting compute job.')
// return
// }
// LoggerInstance.log('[compute] Starting compute job response: ', response)
// await checkPreviousOrders(selectedAlgorithmAsset)
// await checkPreviousOrders(asset)
// setIsPublished(true)
return 'dummy'
} catch (error) {
await checkPreviousOrders(selectedAlgorithmAsset)
await checkPreviousOrders(asset)