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:
parent
0085174e8d
commit
27665c277d
@ -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 {
|
import {
|
||||||
Asset,
|
Asset,
|
||||||
ServiceComputeOptions,
|
ServiceComputeOptions,
|
||||||
PublisherTrustedAlgorithm,
|
PublisherTrustedAlgorithm,
|
||||||
getHash,
|
getHash,
|
||||||
LoggerInstance
|
LoggerInstance,
|
||||||
|
ComputeAlgorithm,
|
||||||
|
DDO,
|
||||||
|
Service
|
||||||
} from '@oceanprotocol/lib'
|
} from '@oceanprotocol/lib'
|
||||||
import { CancelToken } from 'axios'
|
import { CancelToken } from 'axios'
|
||||||
import { gql } from 'urql'
|
import { gql } from 'urql'
|
||||||
@ -29,6 +21,7 @@ import { getServiceById, getServiceByName } from './ddo'
|
|||||||
import { getOceanConfig } from './ocean'
|
import { getOceanConfig } from './ocean'
|
||||||
import { SortTermOptions } from 'src/@types/aquarius/SearchQuery'
|
import { SortTermOptions } from 'src/@types/aquarius/SearchQuery'
|
||||||
import { AssetSelectionAsset } from '@shared/FormFields/AssetSelection'
|
import { AssetSelectionAsset } from '@shared/FormFields/AssetSelection'
|
||||||
|
import { transformAssetToAssetSelection } from './assetConvertor'
|
||||||
|
|
||||||
const getComputeOrders = gql`
|
const getComputeOrders = gql`
|
||||||
query ComputeOrders($user: String!) {
|
query ComputeOrders($user: String!) {
|
||||||
@ -121,7 +114,7 @@ export async function isOrderable(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getQuerryString(
|
export function getQuerryString(
|
||||||
trustedAlgorithmList: PublisherTrustedAlgorithm[],
|
trustedAlgorithmList: PublisherTrustedAlgorithm[],
|
||||||
chainId?: number
|
chainId?: number
|
||||||
): SearchQuery {
|
): SearchQuery {
|
||||||
@ -132,11 +125,12 @@ function getQuerryString(
|
|||||||
sort: { sortBy: SortTermOptions.Created },
|
sort: { sortBy: SortTermOptions.Created },
|
||||||
filters: [
|
filters: [
|
||||||
getFilterTerm('metadata.type', 'algorithm'),
|
getFilterTerm('metadata.type', 'algorithm'),
|
||||||
getFilterTerm('id', algorithmDidList)
|
getFilterTerm('_id', algorithmDidList)
|
||||||
]
|
]
|
||||||
} as BaseQueryParams
|
} as BaseQueryParams
|
||||||
|
|
||||||
const query = generateBaseQuery(baseParams)
|
const query = generateBaseQuery(baseParams)
|
||||||
|
console.log('querry', query)
|
||||||
return query
|
return query
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -145,12 +139,14 @@ export async function getAlgorithmsForAsset(
|
|||||||
token: CancelToken
|
token: CancelToken
|
||||||
): Promise<Asset[]> {
|
): Promise<Asset[]> {
|
||||||
const computeService: Service = getServiceByName(asset, 'compute')
|
const computeService: Service = getServiceByName(asset, 'compute')
|
||||||
|
console.log('computeService: ', computeService)
|
||||||
let algorithms: Asset[]
|
let algorithms: Asset[]
|
||||||
if (
|
if (
|
||||||
!computeService.compute ||
|
!computeService.compute ||
|
||||||
!computeService.compute.publisherTrustedAlgorithms ||
|
!computeService.compute.publisherTrustedAlgorithms ||
|
||||||
computeService.compute.publisherTrustedAlgorithms.length === 0
|
computeService.compute.publisherTrustedAlgorithms.length === 0
|
||||||
) {
|
) {
|
||||||
|
console.log('computeService: []')
|
||||||
algorithms = []
|
algorithms = []
|
||||||
} else {
|
} else {
|
||||||
const gueryResults = await queryMetadata(
|
const gueryResults = await queryMetadata(
|
||||||
@ -160,6 +156,7 @@ export async function getAlgorithmsForAsset(
|
|||||||
),
|
),
|
||||||
token
|
token
|
||||||
)
|
)
|
||||||
|
console.log('gueryResults: ', gueryResults)
|
||||||
algorithms = gueryResults?.results
|
algorithms = gueryResults?.results
|
||||||
}
|
}
|
||||||
return algorithms
|
return algorithms
|
||||||
@ -167,8 +164,7 @@ export async function getAlgorithmsForAsset(
|
|||||||
|
|
||||||
export async function getAlgorithmAssetSelectionList(
|
export async function getAlgorithmAssetSelectionList(
|
||||||
asset: Asset,
|
asset: Asset,
|
||||||
algorithms: Asset[],
|
algorithms: Asset[]
|
||||||
token: CancelToken
|
|
||||||
): Promise<AssetSelectionAsset[]> {
|
): Promise<AssetSelectionAsset[]> {
|
||||||
const computeService: Service = getServiceByName(asset, 'compute')
|
const computeService: Service = getServiceByName(asset, 'compute')
|
||||||
let algorithmSelectionList: AssetSelectionAsset[]
|
let algorithmSelectionList: AssetSelectionAsset[]
|
||||||
@ -179,11 +175,10 @@ export async function getAlgorithmAssetSelectionList(
|
|||||||
) {
|
) {
|
||||||
algorithmSelectionList = []
|
algorithmSelectionList = []
|
||||||
} else {
|
} else {
|
||||||
algorithmSelectionList = await transformDDOToAssetSelection(
|
algorithmSelectionList = await transformAssetToAssetSelection(
|
||||||
computeService?.serviceEndpoint,
|
computeService?.serviceEndpoint,
|
||||||
algorithms,
|
algorithms,
|
||||||
[],
|
[]
|
||||||
token
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
return algorithmSelectionList
|
return algorithmSelectionList
|
||||||
|
@ -10,7 +10,10 @@ export default function Blockies({
|
|||||||
className?: string
|
className?: string
|
||||||
}): ReactElement {
|
}): ReactElement {
|
||||||
if (!accountId) return null
|
if (!accountId) return null
|
||||||
const blockies = toDataUrl(accountId)
|
|
||||||
|
// TODO: just put this back once finished
|
||||||
|
// const blockies = toDataUrl(accountId)
|
||||||
|
const blockies = 'randomstring12345'
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<img
|
<img
|
||||||
|
@ -41,7 +41,8 @@ import { getServiceByName, secondsToString } from '@utils/ddo'
|
|||||||
import {
|
import {
|
||||||
isOrderable,
|
isOrderable,
|
||||||
getAlgorithmAssetSelectionList,
|
getAlgorithmAssetSelectionList,
|
||||||
getAlgorithmsForAsset
|
getAlgorithmsForAsset,
|
||||||
|
getQuerryString
|
||||||
} from '@utils/compute'
|
} from '@utils/compute'
|
||||||
import AssetSelection, {
|
import AssetSelection, {
|
||||||
AssetSelectionAsset
|
AssetSelectionAsset
|
||||||
@ -143,28 +144,9 @@ export default function Compute({
|
|||||||
setHasAlgoAssetDatatoken(Number(AssetDtBalance) >= 1)
|
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[]> {
|
async function getAlgorithmList(): Promise<AssetSelectionAsset[]> {
|
||||||
const source = axios.CancelToken.source()
|
const source = axios.CancelToken.source()
|
||||||
const computeService = ddo.services[0]
|
const computeService = asset.services[0]
|
||||||
let algorithmSelectionList: AssetSelectionAsset[]
|
let algorithmSelectionList: AssetSelectionAsset[]
|
||||||
if (
|
if (
|
||||||
!computeService.compute ||
|
!computeService.compute ||
|
||||||
@ -176,7 +158,7 @@ export default function Compute({
|
|||||||
const gueryResults = await queryMetadata(
|
const gueryResults = await queryMetadata(
|
||||||
getQuerryString(
|
getQuerryString(
|
||||||
computeService.compute.publisherTrustedAlgorithms,
|
computeService.compute.publisherTrustedAlgorithms,
|
||||||
ddo.chainId
|
asset.chainId
|
||||||
),
|
),
|
||||||
source.token
|
source.token
|
||||||
)
|
)
|
||||||
@ -220,14 +202,13 @@ export default function Compute({
|
|||||||
if (!asset) return
|
if (!asset) return
|
||||||
|
|
||||||
getAlgorithmsForAsset(asset, newCancelToken()).then((algorithmsAssets) => {
|
getAlgorithmsForAsset(asset, newCancelToken()).then((algorithmsAssets) => {
|
||||||
|
console.log('getAlgorithmsForAsset', algorithmsAssets)
|
||||||
setDdoAlgorithmList(algorithmsAssets)
|
setDdoAlgorithmList(algorithmsAssets)
|
||||||
getAlgorithmAssetSelectionList(
|
getAlgorithmAssetSelectionList(asset, algorithmsAssets).then(
|
||||||
asset,
|
(algorithmSelectionList) => {
|
||||||
algorithmsAssets,
|
|
||||||
newCancelToken()
|
|
||||||
).then((algorithmSelectionList) => {
|
|
||||||
setAlgorithmList(algorithmSelectionList)
|
setAlgorithmList(algorithmSelectionList)
|
||||||
})
|
}
|
||||||
|
)
|
||||||
})
|
})
|
||||||
}, [asset])
|
}, [asset])
|
||||||
|
|
||||||
@ -271,403 +252,382 @@ export default function Compute({
|
|||||||
|
|
||||||
async function startJob(algorithmId: string): Promise<string> {
|
async function startJob(algorithmId: string): Promise<string> {
|
||||||
try {
|
try {
|
||||||
setIsJobStarting(true)
|
// setIsJobStarting(true)
|
||||||
setIsPublished(false) // would be nice to rename this
|
// setIsPublished(false) // would be nice to rename this
|
||||||
setError(undefined)
|
// setError(undefined)
|
||||||
|
// const computeService = getServiceByName(asset, 'compute')
|
||||||
const computeService = getServiceByName(asset, 'compute')
|
// const serviceAlgo = getServiceByName(selectedAlgorithmAsset, 'access')
|
||||||
const serviceAlgo = getServiceByName(selectedAlgorithmAsset, 'access')
|
// ? getServiceByName(selectedAlgorithmAsset, 'access')
|
||||||
? getServiceByName(selectedAlgorithmAsset, 'access')
|
// : getServiceByName(selectedAlgorithmAsset, 'compute')
|
||||||
: getServiceByName(selectedAlgorithmAsset, 'compute')
|
// const computeAlgorithm: ComputeAlgorithm = {
|
||||||
|
// documentId: selectedAlgorithmAsset.id,
|
||||||
const computeAlgorithm: ComputeAlgorithm = {
|
// serviceId: selectedAlgorithmAsset.services[0].id
|
||||||
documentId: selectedAlgorithmAsset.id,
|
// }
|
||||||
serviceId: selectedAlgorithmAsset.services[0].id
|
// const allowed = await isOrderable(
|
||||||
}
|
// asset,
|
||||||
|
// computeService.id,
|
||||||
const allowed = await isOrderable(
|
// computeAlgorithm,
|
||||||
asset,
|
// selectedAlgorithmAsset
|
||||||
computeService.id,
|
// )
|
||||||
computeAlgorithm,
|
// LoggerInstance.log('[compute] Is data set orderable?', allowed)
|
||||||
selectedAlgorithmAsset
|
// if (!allowed) {
|
||||||
)
|
// setError(
|
||||||
LoggerInstance.log('[compute] Is data set orderable?', allowed)
|
// 'Data set is not orderable in combination with selected algorithm.'
|
||||||
|
// )
|
||||||
if (!allowed) {
|
// LoggerInstance.error(
|
||||||
setError(
|
// '[compute] Error starting compute job. Dataset is not orderable in combination with selected algorithm.'
|
||||||
'Data set is not orderable in combination with selected algorithm.'
|
// )
|
||||||
)
|
// return
|
||||||
LoggerInstance.error(
|
// }
|
||||||
'[compute] Error starting compute job. Dataset is not orderable in combination with selected algorithm.'
|
// let assetOrderId = hasPreviousDatasetOrder ? previousDatasetOrderId : ''
|
||||||
)
|
// if (!hasPreviousDatasetOrder) {
|
||||||
return
|
// // going to move/replace part of this logic when the use consume hook will be ready
|
||||||
}
|
// const initializeData = await ProviderInstance.initialize(
|
||||||
|
// asset.id,
|
||||||
let assetOrderId = hasPreviousDatasetOrder ? previousDatasetOrderId : ''
|
// asset.services[0].id,
|
||||||
|
// 0,
|
||||||
if (!hasPreviousDatasetOrder) {
|
// accountId,
|
||||||
// going to move/replace part of this logic when the use consume hook will be ready
|
// asset.services[0].serviceEndpoint // to check
|
||||||
const initializeData = await ProviderInstance.initialize(
|
// )
|
||||||
asset.id,
|
// const providerFees: ProviderFees = {
|
||||||
asset.services[0].id,
|
// providerFeeAddress: initializeData.providerFee.providerFeeAddress,
|
||||||
0,
|
// providerFeeToken: initializeData.providerFee.providerFeeToken,
|
||||||
accountId,
|
// providerFeeAmount: initializeData.providerFee.providerFeeAmount,
|
||||||
asset.services[0].serviceEndpoint // to check
|
// v: initializeData.providerFee.v,
|
||||||
)
|
// r: initializeData.providerFee.r,
|
||||||
const providerFees: ProviderFees = {
|
// s: initializeData.providerFee.s,
|
||||||
providerFeeAddress: initializeData.providerFee.providerFeeAddress,
|
// providerData: initializeData.providerFee.providerData,
|
||||||
providerFeeToken: initializeData.providerFee.providerFeeToken,
|
// validUntil: initializeData.providerFee.validUntil
|
||||||
providerFeeAmount: initializeData.providerFee.providerFeeAmount,
|
// }
|
||||||
v: initializeData.providerFee.v,
|
// if (!hasDatatoken) {
|
||||||
r: initializeData.providerFee.r,
|
// let tx: TransactionReceipt
|
||||||
s: initializeData.providerFee.s,
|
// switch (accessDetails?.type) {
|
||||||
providerData: initializeData.providerFee.providerData,
|
// case 'dynamic': {
|
||||||
validUntil: initializeData.providerFee.validUntil
|
// const oceanAmmount = new Decimal(accessDetails.price)
|
||||||
}
|
// .times(1.05)
|
||||||
if (!hasDatatoken) {
|
// .toString()
|
||||||
let tx: TransactionReceipt
|
// const maxPrice = new Decimal(accessDetails.price)
|
||||||
switch (accessDetails?.type) {
|
// .times(2)
|
||||||
case 'dynamic': {
|
// .toString()
|
||||||
const oceanAmmount = new Decimal(accessDetails.price)
|
// const poolInstance = new Pool(web3)
|
||||||
.times(1.05)
|
// if (
|
||||||
.toString()
|
// new Decimal('1').greaterThan(
|
||||||
const maxPrice = new Decimal(accessDetails.price)
|
// await poolInstance.getReserve(
|
||||||
.times(2)
|
// accessDetails.addressOrId,
|
||||||
.toString()
|
// accessDetails.datatoken.address
|
||||||
const poolInstance = new Pool(web3)
|
// )
|
||||||
if (
|
// )
|
||||||
new Decimal('1').greaterThan(
|
// ) {
|
||||||
await poolInstance.getReserve(
|
// LoggerInstance.error(
|
||||||
accessDetails.addressOrId,
|
// 'ERROR: Buy quantity exceeds quantity allowed'
|
||||||
accessDetails.datatoken.address
|
// )
|
||||||
)
|
// }
|
||||||
)
|
// const calcInGivenOut = await poolInstance.getAmountInExactOut(
|
||||||
) {
|
// accessDetails.addressOrId,
|
||||||
LoggerInstance.error(
|
// accessDetails.baseToken.address,
|
||||||
'ERROR: Buy quantity exceeds quantity allowed'
|
// accessDetails.datatoken.address,
|
||||||
)
|
// '1',
|
||||||
}
|
// '0.1'
|
||||||
const calcInGivenOut = await poolInstance.getAmountInExactOut(
|
// )
|
||||||
accessDetails.addressOrId,
|
// if (new Decimal(calcInGivenOut).greaterThan(oceanAmmount)) {
|
||||||
accessDetails.baseToken.address,
|
// this.logger.error('ERROR: Not enough Ocean Tokens')
|
||||||
accessDetails.datatoken.address,
|
// return null
|
||||||
'1',
|
// }
|
||||||
'0.1'
|
// const approvetx = await approve(
|
||||||
)
|
// web3,
|
||||||
if (new Decimal(calcInGivenOut).greaterThan(oceanAmmount)) {
|
// accountId,
|
||||||
this.logger.error('ERROR: Not enough Ocean Tokens')
|
// accessDetails.baseToken.address,
|
||||||
return null
|
// accountId,
|
||||||
}
|
// '1'
|
||||||
|
// )
|
||||||
const approvetx = await approve(
|
// if (!approvetx) {
|
||||||
web3,
|
// LoggerInstance.error(
|
||||||
accountId,
|
// 'ERROR: Failed to call approve OCEAN token'
|
||||||
accessDetails.baseToken.address,
|
// )
|
||||||
accountId,
|
// }
|
||||||
'1'
|
// const tokenInOutMarket: TokenInOutMarket = {
|
||||||
)
|
// tokenIn: accessDetails.baseToken.address,
|
||||||
if (!approvetx) {
|
// tokenOut: accessDetails.datatoken.address,
|
||||||
LoggerInstance.error(
|
// marketFeeAddress: appConfig.marketFeeAddress
|
||||||
'ERROR: Failed to call approve OCEAN token'
|
// }
|
||||||
)
|
// const amountsInOutMaxFee: AmountsOutMaxFee = {
|
||||||
}
|
// maxAmountIn: oceanAmmount,
|
||||||
const tokenInOutMarket: TokenInOutMarket = {
|
// tokenAmountOut: '1',
|
||||||
tokenIn: accessDetails.baseToken.address,
|
// swapMarketFee: '0.1'
|
||||||
tokenOut: accessDetails.datatoken.address,
|
// }
|
||||||
marketFeeAddress: appConfig.marketFeeAddress
|
// const tx = await poolInstance.swapExactAmountOut(
|
||||||
}
|
// accountId,
|
||||||
const amountsInOutMaxFee: AmountsOutMaxFee = {
|
// accessDetails.addressOrId,
|
||||||
maxAmountIn: oceanAmmount,
|
// tokenInOutMarket,
|
||||||
tokenAmountOut: '1',
|
// amountsInOutMaxFee
|
||||||
swapMarketFee: '0.1'
|
// )
|
||||||
}
|
// break
|
||||||
const tx = await poolInstance.swapExactAmountOut(
|
// }
|
||||||
accountId,
|
// case 'fixed': {
|
||||||
accessDetails.addressOrId,
|
// const datatokenInstance = new Datatoken(web3)
|
||||||
tokenInOutMarket,
|
// const order: OrderParams = {
|
||||||
amountsInOutMaxFee
|
// consumer: accountId,
|
||||||
)
|
// serviceIndex: 1,
|
||||||
|
// _providerFees: providerFees
|
||||||
break
|
// }
|
||||||
}
|
// const fre: FreOrderParams = {
|
||||||
case 'fixed': {
|
// exchangeContract: accessDetails.addressOrId,
|
||||||
const datatokenInstance = new Datatoken(web3)
|
// exchangeId:
|
||||||
const order: OrderParams = {
|
// '0x7ac824fef114255e5e3521a161ef692ec32003916fb6f3fe985cb74790d053ca',
|
||||||
consumer: accountId,
|
// maxBaseTokenAmount: '1',
|
||||||
serviceIndex: 1,
|
// swapMarketFee: web3.utils.toWei('0.1'),
|
||||||
_providerFees: providerFees
|
// marketFeeAddress: appConfig.marketFeeAddress
|
||||||
}
|
// }
|
||||||
const fre: FreOrderParams = {
|
// tx = await datatokenInstance.buyFromFreAndOrder(
|
||||||
exchangeContract: accessDetails.addressOrId,
|
// asset.datatokens[0].address,
|
||||||
exchangeId:
|
// accountId,
|
||||||
'0x7ac824fef114255e5e3521a161ef692ec32003916fb6f3fe985cb74790d053ca',
|
// order,
|
||||||
maxBaseTokenAmount: '1',
|
// fre
|
||||||
swapMarketFee: web3.utils.toWei('0.1'),
|
// )
|
||||||
marketFeeAddress: appConfig.marketFeeAddress
|
// assetOrderId = tx.transactionHash
|
||||||
}
|
// break
|
||||||
tx = await datatokenInstance.buyFromFreAndOrder(
|
// }
|
||||||
asset.datatokens[0].address,
|
// case 'free': {
|
||||||
accountId,
|
// const datatokenInstance = new Datatoken(web3)
|
||||||
order,
|
// const order: OrderParams = {
|
||||||
fre
|
// consumer: accountId,
|
||||||
)
|
// serviceIndex: 0,
|
||||||
assetOrderId = tx.transactionHash
|
// _providerFees: providerFees
|
||||||
|
// }
|
||||||
break
|
// const fre: FreOrderParams = {
|
||||||
}
|
// exchangeContract: accessDetails.addressOrId,
|
||||||
case 'free': {
|
// exchangeId:
|
||||||
const datatokenInstance = new Datatoken(web3)
|
// '0x7ac824fef114255e5e3521a161ef692ec32003916fb6f3fe985cb74790d053ca',
|
||||||
const order: OrderParams = {
|
// maxBaseTokenAmount: '1',
|
||||||
consumer: accountId,
|
// swapMarketFee: web3.utils.toWei('0.1'),
|
||||||
serviceIndex: 0,
|
// marketFeeAddress: appConfig.marketFeeAddress
|
||||||
_providerFees: providerFees
|
// }
|
||||||
}
|
// tx = await datatokenInstance.buyFromDispenserAndOrder(
|
||||||
const fre: FreOrderParams = {
|
// asset.datatokens[0].address,
|
||||||
exchangeContract: accessDetails.addressOrId,
|
// accountId,
|
||||||
exchangeId:
|
// order,
|
||||||
'0x7ac824fef114255e5e3521a161ef692ec32003916fb6f3fe985cb74790d053ca',
|
// accessDetails.addressOrId
|
||||||
maxBaseTokenAmount: '1',
|
// )
|
||||||
swapMarketFee: web3.utils.toWei('0.1'),
|
// assetOrderId = tx.transactionHash
|
||||||
marketFeeAddress: appConfig.marketFeeAddress
|
// if (!tx) {
|
||||||
}
|
// setError('Error buying datatoken.')
|
||||||
tx = await datatokenInstance.buyFromDispenserAndOrder(
|
// LoggerInstance.error(
|
||||||
asset.datatokens[0].address,
|
// '[compute] Error buying datatoken for data set ',
|
||||||
accountId,
|
// asset.id
|
||||||
order,
|
// )
|
||||||
accessDetails.addressOrId
|
// return
|
||||||
)
|
// }
|
||||||
assetOrderId = tx.transactionHash
|
// break
|
||||||
if (!tx) {
|
// }
|
||||||
setError('Error buying datatoken.')
|
// }
|
||||||
LoggerInstance.error(
|
// } else {
|
||||||
'[compute] Error buying datatoken for data set ',
|
// const datatokenInstance = new Datatoken(web3)
|
||||||
asset.id
|
// const tx = await datatokenInstance.startOrder(
|
||||||
)
|
// asset.datatokens[0].address,
|
||||||
return
|
// accountId,
|
||||||
}
|
// initializeData.computeAddress,
|
||||||
break
|
// 0,
|
||||||
}
|
// providerFees
|
||||||
}
|
// )
|
||||||
} else {
|
// assetOrderId = tx.transactionHash
|
||||||
const datatokenInstance = new Datatoken(web3)
|
// }
|
||||||
const tx = await datatokenInstance.startOrder(
|
// }
|
||||||
asset.datatokens[0].address,
|
// let algorithmAssetOrderId = hasPreviousAlgorithmOrder
|
||||||
accountId,
|
// ? previousAlgorithmOrderId
|
||||||
initializeData.computeAddress,
|
// : ''
|
||||||
0,
|
// // add method for this logic
|
||||||
providerFees
|
// if (!hasPreviousAlgorithmOrder) {
|
||||||
)
|
// // going to move replace part of this logic when the use consume hook will be ready
|
||||||
assetOrderId = tx.transactionHash
|
// const initializeData = await ProviderInstance.initialize(
|
||||||
}
|
// selectedAlgorithmAsset.id,
|
||||||
}
|
// selectedAlgorithmAsset.services[0].id,
|
||||||
|
// 0,
|
||||||
let algorithmAssetOrderId = hasPreviousAlgorithmOrder
|
// accountId,
|
||||||
? previousAlgorithmOrderId
|
// selectedAlgorithmAsset.services[0].serviceEndpoint // to check
|
||||||
: ''
|
// )
|
||||||
|
// const providerFees: ProviderFees = {
|
||||||
// add method for this logic
|
// providerFeeAddress: initializeData.providerFee.providerFeeAddress,
|
||||||
if (!hasPreviousAlgorithmOrder) {
|
// providerFeeToken: initializeData.providerFee.providerFeeToken,
|
||||||
// going to move replace part of this logic when the use consume hook will be ready
|
// providerFeeAmount: initializeData.providerFee.providerFeeAmount,
|
||||||
const initializeData = await ProviderInstance.initialize(
|
// v: initializeData.providerFee.v,
|
||||||
selectedAlgorithmAsset.id,
|
// r: initializeData.providerFee.r,
|
||||||
selectedAlgorithmAsset.services[0].id,
|
// s: initializeData.providerFee.s,
|
||||||
0,
|
// providerData: initializeData.providerFee.providerData,
|
||||||
accountId,
|
// validUntil: initializeData.providerFee.validUntil
|
||||||
selectedAlgorithmAsset.services[0].serviceEndpoint // to check
|
// }
|
||||||
)
|
// if (!hasAlgoAssetDatatoken) {
|
||||||
const providerFees: ProviderFees = {
|
// let tx: TransactionReceipt
|
||||||
providerFeeAddress: initializeData.providerFee.providerFeeAddress,
|
// switch (algorithmConsumeDetails?.type) {
|
||||||
providerFeeToken: initializeData.providerFee.providerFeeToken,
|
// case 'dynamic': {
|
||||||
providerFeeAmount: initializeData.providerFee.providerFeeAmount,
|
// const oceanAmmount = new Decimal(algorithmConsumeDetails.price)
|
||||||
v: initializeData.providerFee.v,
|
// .times(1.05)
|
||||||
r: initializeData.providerFee.r,
|
// .toString()
|
||||||
s: initializeData.providerFee.s,
|
// const maxPrice = new Decimal(algorithmConsumeDetails.price)
|
||||||
providerData: initializeData.providerFee.providerData,
|
// .times(2)
|
||||||
validUntil: initializeData.providerFee.validUntil
|
// .toString()
|
||||||
}
|
// const poolInstance = new Pool(web3)
|
||||||
if (!hasAlgoAssetDatatoken) {
|
// if (
|
||||||
let tx: TransactionReceipt
|
// new Decimal('1').greaterThan(
|
||||||
switch (algorithmConsumeDetails?.type) {
|
// await poolInstance.getReserve(
|
||||||
case 'dynamic': {
|
// algorithmConsumeDetails.addressOrId,
|
||||||
const oceanAmmount = new Decimal(algorithmConsumeDetails.price)
|
// algorithmConsumeDetails.datatoken.address
|
||||||
.times(1.05)
|
// )
|
||||||
.toString()
|
// )
|
||||||
const maxPrice = new Decimal(algorithmConsumeDetails.price)
|
// ) {
|
||||||
.times(2)
|
// LoggerInstance.error(
|
||||||
.toString()
|
// 'ERROR: Buy quantity exceeds quantity allowed'
|
||||||
const poolInstance = new Pool(web3)
|
// )
|
||||||
if (
|
// }
|
||||||
new Decimal('1').greaterThan(
|
// const calcInGivenOut = await poolInstance.getAmountInExactOut(
|
||||||
await poolInstance.getReserve(
|
// algorithmConsumeDetails.addressOrId,
|
||||||
algorithmConsumeDetails.addressOrId,
|
// algorithmConsumeDetails.baseToken.address,
|
||||||
algorithmConsumeDetails.datatoken.address
|
// algorithmConsumeDetails.datatoken.address,
|
||||||
)
|
// '1',
|
||||||
)
|
// '0.1'
|
||||||
) {
|
// )
|
||||||
LoggerInstance.error(
|
// if (new Decimal(calcInGivenOut).greaterThan(oceanAmmount)) {
|
||||||
'ERROR: Buy quantity exceeds quantity allowed'
|
// this.logger.error('ERROR: Not enough Ocean Tokens')
|
||||||
)
|
// return null
|
||||||
}
|
// }
|
||||||
const calcInGivenOut = await poolInstance.getAmountInExactOut(
|
// const approvetx = await approve(
|
||||||
algorithmConsumeDetails.addressOrId,
|
// web3,
|
||||||
algorithmConsumeDetails.baseToken.address,
|
// accountId,
|
||||||
algorithmConsumeDetails.datatoken.address,
|
// algorithmConsumeDetails.baseToken.address,
|
||||||
'1',
|
// accountId,
|
||||||
'0.1'
|
// '1'
|
||||||
)
|
// )
|
||||||
if (new Decimal(calcInGivenOut).greaterThan(oceanAmmount)) {
|
// if (!approvetx) {
|
||||||
this.logger.error('ERROR: Not enough Ocean Tokens')
|
// LoggerInstance.error(
|
||||||
return null
|
// 'ERROR: Failed to call approve OCEAN token'
|
||||||
}
|
// )
|
||||||
|
// }
|
||||||
const approvetx = await approve(
|
// const tokenInOutMarket: TokenInOutMarket = {
|
||||||
web3,
|
// tokenIn: algorithmConsumeDetails.baseToken.address,
|
||||||
accountId,
|
// tokenOut: algorithmConsumeDetails.datatoken.address,
|
||||||
algorithmConsumeDetails.baseToken.address,
|
// marketFeeAddress: appConfig.marketFeeAddress
|
||||||
accountId,
|
// }
|
||||||
'1'
|
// const amountsInOutMaxFee: AmountsOutMaxFee = {
|
||||||
)
|
// maxAmountIn: oceanAmmount,
|
||||||
if (!approvetx) {
|
// tokenAmountOut: '1',
|
||||||
LoggerInstance.error(
|
// swapMarketFee: '0.1'
|
||||||
'ERROR: Failed to call approve OCEAN token'
|
// }
|
||||||
)
|
// const tx = await poolInstance.swapExactAmountOut(
|
||||||
}
|
// accountId,
|
||||||
const tokenInOutMarket: TokenInOutMarket = {
|
// algorithmConsumeDetails.addressOrId,
|
||||||
tokenIn: algorithmConsumeDetails.baseToken.address,
|
// tokenInOutMarket,
|
||||||
tokenOut: algorithmConsumeDetails.datatoken.address,
|
// amountsInOutMaxFee
|
||||||
marketFeeAddress: appConfig.marketFeeAddress
|
// )
|
||||||
}
|
// break
|
||||||
const amountsInOutMaxFee: AmountsOutMaxFee = {
|
// }
|
||||||
maxAmountIn: oceanAmmount,
|
// case 'fixed': {
|
||||||
tokenAmountOut: '1',
|
// const datatokenInstance = new Datatoken(web3)
|
||||||
swapMarketFee: '0.1'
|
// const order: OrderParams = {
|
||||||
}
|
// consumer: accountId,
|
||||||
const tx = await poolInstance.swapExactAmountOut(
|
// serviceIndex: 1,
|
||||||
accountId,
|
// _providerFees: providerFees
|
||||||
algorithmConsumeDetails.addressOrId,
|
// }
|
||||||
tokenInOutMarket,
|
// const fre: FreOrderParams = {
|
||||||
amountsInOutMaxFee
|
// exchangeContract: algorithmConsumeDetails.addressOrId,
|
||||||
)
|
// exchangeId:
|
||||||
break
|
// '0x7ac824fef114255e5e3521a161ef692ec32003916fb6f3fe985cb74790d053ca',
|
||||||
}
|
// maxBaseTokenAmount: '1',
|
||||||
case 'fixed': {
|
// swapMarketFee: web3.utils.toWei('0.1'), // to update
|
||||||
const datatokenInstance = new Datatoken(web3)
|
// marketFeeAddress: appConfig.marketFeeAddress
|
||||||
const order: OrderParams = {
|
// }
|
||||||
consumer: accountId,
|
// tx = await datatokenInstance.buyFromFreAndOrder(
|
||||||
serviceIndex: 1,
|
// selectedAlgorithmAsset.datatokens[0].address,
|
||||||
_providerFees: providerFees
|
// accountId,
|
||||||
}
|
// order,
|
||||||
const fre: FreOrderParams = {
|
// fre
|
||||||
exchangeContract: algorithmConsumeDetails.addressOrId,
|
// )
|
||||||
exchangeId:
|
// algorithmAssetOrderId = tx.transactionHash
|
||||||
'0x7ac824fef114255e5e3521a161ef692ec32003916fb6f3fe985cb74790d053ca',
|
// break
|
||||||
maxBaseTokenAmount: '1',
|
// }
|
||||||
swapMarketFee: web3.utils.toWei('0.1'), // to update
|
// case 'free': {
|
||||||
marketFeeAddress: appConfig.marketFeeAddress
|
// const datatokenInstance = new Datatoken(web3)
|
||||||
}
|
// const order: OrderParams = {
|
||||||
tx = await datatokenInstance.buyFromFreAndOrder(
|
// consumer: accountId,
|
||||||
selectedAlgorithmAsset.datatokens[0].address,
|
// serviceIndex: 1,
|
||||||
accountId,
|
// _providerFees: providerFees
|
||||||
order,
|
// }
|
||||||
fre
|
// const fre: FreOrderParams = {
|
||||||
)
|
// exchangeContract: algorithmConsumeDetails.addressOrId,
|
||||||
algorithmAssetOrderId = tx.transactionHash
|
// exchangeId:
|
||||||
break
|
// '0x7ac824fef114255e5e3521a161ef692ec32003916fb6f3fe985cb74790d053ca',
|
||||||
}
|
// maxBaseTokenAmount: '1',
|
||||||
case 'free': {
|
// swapMarketFee: web3.utils.toWei('0.1'), // to update
|
||||||
const datatokenInstance = new Datatoken(web3)
|
// marketFeeAddress: appConfig.marketFeeAddress
|
||||||
const order: OrderParams = {
|
// }
|
||||||
consumer: accountId,
|
// tx = await datatokenInstance.buyFromDispenserAndOrder(
|
||||||
serviceIndex: 1,
|
// selectedAlgorithmAsset.datatokens[0].address,
|
||||||
_providerFees: providerFees
|
// accountId,
|
||||||
}
|
// order,
|
||||||
const fre: FreOrderParams = {
|
// algorithmConsumeDetails.addressOrId
|
||||||
exchangeContract: algorithmConsumeDetails.addressOrId,
|
// )
|
||||||
exchangeId:
|
// algorithmAssetOrderId = tx.transactionHash
|
||||||
'0x7ac824fef114255e5e3521a161ef692ec32003916fb6f3fe985cb74790d053ca',
|
// break
|
||||||
maxBaseTokenAmount: '1',
|
// }
|
||||||
swapMarketFee: web3.utils.toWei('0.1'), // to update
|
// }
|
||||||
marketFeeAddress: appConfig.marketFeeAddress
|
// } else {
|
||||||
}
|
// const datatokenInstance = new Datatoken(web3)
|
||||||
tx = await datatokenInstance.buyFromDispenserAndOrder(
|
// const tx = await datatokenInstance.startOrder(
|
||||||
selectedAlgorithmAsset.datatokens[0].address,
|
// selectedAlgorithmAsset.datatokens[0].address,
|
||||||
accountId,
|
// accountId,
|
||||||
order,
|
// initializeData.computeAddress,
|
||||||
algorithmConsumeDetails.addressOrId
|
// 0,
|
||||||
)
|
// providerFees
|
||||||
algorithmAssetOrderId = tx.transactionHash
|
// )
|
||||||
break
|
// algorithmAssetOrderId = tx.transactionHash
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
} else {
|
// LoggerInstance.log(
|
||||||
const datatokenInstance = new Datatoken(web3)
|
// `[compute] Got ${
|
||||||
const tx = await datatokenInstance.startOrder(
|
// hasPreviousDatasetOrder ? 'existing' : 'new'
|
||||||
selectedAlgorithmAsset.datatokens[0].address,
|
// } order ID for dataset: `,
|
||||||
accountId,
|
// assetOrderId
|
||||||
initializeData.computeAddress,
|
// )
|
||||||
0,
|
// LoggerInstance.log(
|
||||||
providerFees
|
// `[compute] Got ${
|
||||||
)
|
// hasPreviousAlgorithmOrder ? 'existing' : 'new'
|
||||||
algorithmAssetOrderId = tx.transactionHash
|
// } order ID for algorithm: `,
|
||||||
}
|
// algorithmAssetOrderId
|
||||||
}
|
// )
|
||||||
|
// if (!assetOrderId || !algorithmAssetOrderId) {
|
||||||
LoggerInstance.log(
|
// setError('Error ordering assets.')
|
||||||
`[compute] Got ${
|
// return
|
||||||
hasPreviousDatasetOrder ? 'existing' : 'new'
|
// }
|
||||||
} order ID for dataset: `,
|
// computeAlgorithm.transferTxId = algorithmAssetOrderId
|
||||||
assetOrderId
|
// LoggerInstance.log('[compute] Starting compute job.')
|
||||||
)
|
// const computeAsset: ComputeAsset = {
|
||||||
|
// documentId: asset.id,
|
||||||
LoggerInstance.log(
|
// serviceId: asset.services[0].id,
|
||||||
`[compute] Got ${
|
// transferTxId: assetOrderId
|
||||||
hasPreviousAlgorithmOrder ? 'existing' : 'new'
|
// }
|
||||||
} order ID for algorithm: `,
|
// computeAlgorithm.transferTxId = algorithmAssetOrderId
|
||||||
algorithmAssetOrderId
|
// const output: ComputeOutput = {
|
||||||
)
|
// publishAlgorithmLog: true,
|
||||||
|
// publishOutput: true
|
||||||
if (!assetOrderId || !algorithmAssetOrderId) {
|
// }
|
||||||
setError('Error ordering assets.')
|
// const response = await ProviderInstance.computeStart(
|
||||||
return
|
// asset.services[0].serviceEndpoint,
|
||||||
}
|
// web3,
|
||||||
|
// accountId,
|
||||||
computeAlgorithm.transferTxId = algorithmAssetOrderId
|
// 'env1',
|
||||||
LoggerInstance.log('[compute] Starting compute job.')
|
// computeAsset,
|
||||||
|
// computeAlgorithm,
|
||||||
const computeAsset: ComputeAsset = {
|
// newAbortController(),
|
||||||
documentId: asset.id,
|
// null,
|
||||||
serviceId: asset.services[0].id,
|
// output
|
||||||
transferTxId: assetOrderId
|
// )
|
||||||
}
|
// if (!response) {
|
||||||
computeAlgorithm.transferTxId = algorithmAssetOrderId
|
// setError('Error starting compute job.')
|
||||||
|
// return
|
||||||
const output: ComputeOutput = {
|
// }
|
||||||
publishAlgorithmLog: true,
|
// LoggerInstance.log('[compute] Starting compute job response: ', response)
|
||||||
publishOutput: true
|
// await checkPreviousOrders(selectedAlgorithmAsset)
|
||||||
}
|
// await checkPreviousOrders(asset)
|
||||||
|
// setIsPublished(true)
|
||||||
const response = await ProviderInstance.computeStart(
|
return 'dummy'
|
||||||
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)
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
await checkPreviousOrders(selectedAlgorithmAsset)
|
await checkPreviousOrders(selectedAlgorithmAsset)
|
||||||
await checkPreviousOrders(asset)
|
await checkPreviousOrders(asset)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user