mirror of
https://github.com/oceanprotocol/market.git
synced 2024-12-02 05:57:29 +01:00
wip compute initialize
This commit is contained in:
parent
ab48abe73c
commit
15af847a9c
@ -8,7 +8,12 @@ import {
|
|||||||
TokensPriceQuery,
|
TokensPriceQuery,
|
||||||
TokensPriceQuery_tokens as TokensPrice
|
TokensPriceQuery_tokens as TokensPrice
|
||||||
} from '../@types/subgraph/TokensPriceQuery'
|
} from '../@types/subgraph/TokensPriceQuery'
|
||||||
import { Asset, LoggerInstance, ProviderInstance } from '@oceanprotocol/lib'
|
import {
|
||||||
|
Asset,
|
||||||
|
LoggerInstance,
|
||||||
|
ProviderFees,
|
||||||
|
ProviderInstance
|
||||||
|
} from '@oceanprotocol/lib'
|
||||||
import { AssetExtended } from 'src/@types/AssetExtended'
|
import { AssetExtended } from 'src/@types/AssetExtended'
|
||||||
import { calcInGivenOut } from './pool'
|
import { calcInGivenOut } from './pool'
|
||||||
import { getFixedBuyPrice } from './fixedRateExchange'
|
import { getFixedBuyPrice } from './fixedRateExchange'
|
||||||
@ -238,8 +243,7 @@ export async function getOrderPriceAndFees(
|
|||||||
asset: AssetExtended,
|
asset: AssetExtended,
|
||||||
accountId?: string,
|
accountId?: string,
|
||||||
paramsForPool?: CalcInGivenOutParams,
|
paramsForPool?: CalcInGivenOutParams,
|
||||||
computeEnv: string = null,
|
providerFees?: ProviderFees
|
||||||
computeValidUntil: number = null
|
|
||||||
): Promise<OrderPriceAndFees> {
|
): Promise<OrderPriceAndFees> {
|
||||||
const orderPriceAndFee = {
|
const orderPriceAndFee = {
|
||||||
price: '0',
|
price: '0',
|
||||||
@ -258,18 +262,16 @@ export async function getOrderPriceAndFees(
|
|||||||
|
|
||||||
// fetch provider fee
|
// fetch provider fee
|
||||||
|
|
||||||
const initializeData = await ProviderInstance.initialize(
|
const initializeData =
|
||||||
asset?.id,
|
!providerFees &&
|
||||||
asset.services[0].id,
|
(await ProviderInstance.initialize(
|
||||||
0,
|
asset?.id,
|
||||||
accountId,
|
asset.services[0].id,
|
||||||
asset.services[0].serviceEndpoint,
|
0,
|
||||||
null,
|
accountId,
|
||||||
null,
|
asset.services[0].serviceEndpoint
|
||||||
computeEnv,
|
))
|
||||||
computeValidUntil
|
orderPriceAndFee.providerFee = providerFees || initializeData.providerFee
|
||||||
)
|
|
||||||
orderPriceAndFee.providerFee = initializeData.providerFee
|
|
||||||
|
|
||||||
// fetch price and swap fees
|
// fetch price and swap fees
|
||||||
switch (asset?.accessDetails?.type) {
|
switch (asset?.accessDetails?.type) {
|
||||||
|
@ -2,7 +2,11 @@ import {
|
|||||||
approve,
|
approve,
|
||||||
Datatoken,
|
Datatoken,
|
||||||
FreOrderParams,
|
FreOrderParams,
|
||||||
|
LoggerInstance,
|
||||||
OrderParams,
|
OrderParams,
|
||||||
|
ProviderComputeInitialize,
|
||||||
|
ProviderComputeInitializeResults,
|
||||||
|
ProviderFees,
|
||||||
ProviderInstance
|
ProviderInstance
|
||||||
} from '@oceanprotocol/lib'
|
} from '@oceanprotocol/lib'
|
||||||
import { AssetExtended } from 'src/@types/AssetExtended'
|
import { AssetExtended } from 'src/@types/AssetExtended'
|
||||||
@ -15,6 +19,8 @@ import {
|
|||||||
consumeMarketOrderFee,
|
consumeMarketOrderFee,
|
||||||
consumeMarketFixedSwapFee
|
consumeMarketFixedSwapFee
|
||||||
} from '../../app.config'
|
} from '../../app.config'
|
||||||
|
import { buyDtFromPool } from './pool'
|
||||||
|
import { toast } from 'react-toastify'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* For pool you need to buy the datatoken beforehand, this always assumes you want to order the first service
|
* For pool you need to buy the datatoken beforehand, this always assumes you want to order the first service
|
||||||
@ -31,29 +37,26 @@ export async function order(
|
|||||||
asset: AssetExtended,
|
asset: AssetExtended,
|
||||||
orderPriceAndFees: OrderPriceAndFees,
|
orderPriceAndFees: OrderPriceAndFees,
|
||||||
accountId: string,
|
accountId: string,
|
||||||
computeEnv: string = null,
|
providerFees?: ProviderFees,
|
||||||
computeValidUntil: number = null,
|
|
||||||
computeConsumerAddress?: string
|
computeConsumerAddress?: string
|
||||||
): Promise<TransactionReceipt> {
|
): Promise<TransactionReceipt> {
|
||||||
const datatoken = new Datatoken(web3)
|
const datatoken = new Datatoken(web3)
|
||||||
const config = getOceanConfig(asset.chainId)
|
const config = getOceanConfig(asset.chainId)
|
||||||
|
|
||||||
const initializeData = await ProviderInstance.initialize(
|
const initializeData =
|
||||||
asset.id,
|
!providerFees &&
|
||||||
asset.services[0].id,
|
(await ProviderInstance.initialize(
|
||||||
0,
|
asset.id,
|
||||||
accountId,
|
asset.services[0].id,
|
||||||
asset.services[0].serviceEndpoint,
|
0,
|
||||||
null,
|
accountId,
|
||||||
null,
|
asset.services[0].serviceEndpoint
|
||||||
computeEnv,
|
))
|
||||||
computeValidUntil
|
|
||||||
)
|
|
||||||
|
|
||||||
const orderParams = {
|
const orderParams = {
|
||||||
consumer: computeConsumerAddress || accountId,
|
consumer: computeConsumerAddress || accountId,
|
||||||
serviceIndex: 0,
|
serviceIndex: 0,
|
||||||
_providerFee: initializeData.providerFee,
|
_providerFee: providerFees || initializeData.providerFee,
|
||||||
_consumeMarketFee: {
|
_consumeMarketFee: {
|
||||||
consumeMarketFeeAddress: marketFeeAddress,
|
consumeMarketFeeAddress: marketFeeAddress,
|
||||||
consumeMarketFeeAmount: consumeMarketOrderFee,
|
consumeMarketFeeAmount: consumeMarketOrderFee,
|
||||||
@ -99,7 +102,7 @@ export async function order(
|
|||||||
accountId,
|
accountId,
|
||||||
computeConsumerAddress || accountId,
|
computeConsumerAddress || accountId,
|
||||||
0,
|
0,
|
||||||
initializeData.providerFee
|
providerFees || initializeData.providerFee
|
||||||
)
|
)
|
||||||
return tx
|
return tx
|
||||||
}
|
}
|
||||||
@ -121,10 +124,8 @@ export async function order(
|
|||||||
* @param web3
|
* @param web3
|
||||||
* @param asset
|
* @param asset
|
||||||
* @param accountId
|
* @param accountId
|
||||||
* @param accountId validOrderTx
|
* @param validOrderTx
|
||||||
* @param computeEnv
|
* @param providerFees
|
||||||
* @param computeValidUntil
|
|
||||||
* @param computeConsumerAddress
|
|
||||||
* @returns {TransactionReceipt} receipt of the order
|
* @returns {TransactionReceipt} receipt of the order
|
||||||
*/
|
*/
|
||||||
export async function reuseOrder(
|
export async function reuseOrder(
|
||||||
@ -132,28 +133,27 @@ export async function reuseOrder(
|
|||||||
asset: AssetExtended,
|
asset: AssetExtended,
|
||||||
accountId: string,
|
accountId: string,
|
||||||
validOrderTx: string,
|
validOrderTx: string,
|
||||||
computeEnv: string = null,
|
providerFees?: ProviderFees
|
||||||
computeValidUntil: number = null,
|
): Promise<TransactionReceipt> {
|
||||||
computeConsumerAddress?: string
|
|
||||||
) {
|
|
||||||
const datatoken = new Datatoken(web3)
|
const datatoken = new Datatoken(web3)
|
||||||
const initializeData = await ProviderInstance.initialize(
|
const initializeData =
|
||||||
asset.id,
|
!providerFees &&
|
||||||
asset.services[0].id,
|
(await ProviderInstance.initialize(
|
||||||
0,
|
asset.id,
|
||||||
accountId,
|
asset.services[0].id,
|
||||||
asset.services[0].serviceEndpoint,
|
0,
|
||||||
null,
|
accountId,
|
||||||
null,
|
asset.services[0].serviceEndpoint
|
||||||
computeEnv,
|
))
|
||||||
computeValidUntil
|
|
||||||
)
|
|
||||||
const txApprove = await approve(
|
const txApprove = await approve(
|
||||||
web3,
|
web3,
|
||||||
accountId,
|
accountId,
|
||||||
initializeData.providerFee.providerFeeToken,
|
providerFees.providerFeeToken ||
|
||||||
|
initializeData.providerFee.providerFeeToken,
|
||||||
asset.accessDetails.datatoken.address,
|
asset.accessDetails.datatoken.address,
|
||||||
initializeData.providerFee.providerFeeAmount,
|
providerFees.providerFeeAmount ||
|
||||||
|
initializeData.providerFee.providerFeeAmount,
|
||||||
false
|
false
|
||||||
)
|
)
|
||||||
if (!txApprove) {
|
if (!txApprove) {
|
||||||
@ -164,8 +164,62 @@ export async function reuseOrder(
|
|||||||
asset.accessDetails.datatoken.address,
|
asset.accessDetails.datatoken.address,
|
||||||
accountId,
|
accountId,
|
||||||
validOrderTx,
|
validOrderTx,
|
||||||
initializeData.providerFee
|
providerFees || initializeData.providerFee
|
||||||
)
|
)
|
||||||
|
|
||||||
return tx
|
return tx
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles order for compute assets for the following scenarios:
|
||||||
|
* - have validOrder and no providerFees -> then order is valid, providerFees are valid, it returns the valid order value
|
||||||
|
* - have validOrder and providerFees -> then order is valid but providerFees are not valid, we need to call reuseOrder and pay only providerFees
|
||||||
|
* - no validOrder -> we need to call order, to pay 1 DT & providerFees
|
||||||
|
* @param web3
|
||||||
|
* @param asset
|
||||||
|
* @param accountId
|
||||||
|
* @param computeEnv
|
||||||
|
* @param computeValidUntil
|
||||||
|
* @param computeConsumerAddress
|
||||||
|
* @returns {Promise<string>} tx id
|
||||||
|
*/
|
||||||
|
export async function handleComputeOrder(
|
||||||
|
web3: Web3,
|
||||||
|
asset: AssetExtended,
|
||||||
|
orderPriceAndFees: OrderPriceAndFees,
|
||||||
|
accountId: string,
|
||||||
|
hasDatatoken: boolean,
|
||||||
|
initializeData: ProviderComputeInitialize,
|
||||||
|
computeConsumerAddress?: string
|
||||||
|
): Promise<string> {
|
||||||
|
if (initializeData.validOrder && !initializeData.providerFee) {
|
||||||
|
return initializeData.validOrder
|
||||||
|
} else if (initializeData.validOrder) {
|
||||||
|
const tx = await reuseOrder(
|
||||||
|
web3,
|
||||||
|
asset,
|
||||||
|
accountId,
|
||||||
|
initializeData.validOrder,
|
||||||
|
initializeData.providerFee
|
||||||
|
)
|
||||||
|
return tx.transactionHash
|
||||||
|
} else {
|
||||||
|
if (!hasDatatoken && asset?.accessDetails.type === 'dynamic') {
|
||||||
|
const poolTx = await buyDtFromPool(asset?.accessDetails, accountId, web3)
|
||||||
|
LoggerInstance.log('[compute] Buy dt from pool: ', poolTx)
|
||||||
|
if (!poolTx) {
|
||||||
|
toast.error('Failed to buy datatoken from pool!')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const tx = await order(
|
||||||
|
web3,
|
||||||
|
asset,
|
||||||
|
orderPriceAndFees,
|
||||||
|
accountId,
|
||||||
|
initializeData.providerFee,
|
||||||
|
computeConsumerAddress
|
||||||
|
)
|
||||||
|
return tx.transactionHash
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -1,11 +1,50 @@
|
|||||||
import {
|
import {
|
||||||
|
ComputeAlgorithm,
|
||||||
|
ComputeAsset,
|
||||||
|
ComputeEnvironment,
|
||||||
downloadFileBrowser,
|
downloadFileBrowser,
|
||||||
FileMetadata,
|
FileMetadata,
|
||||||
LoggerInstance,
|
LoggerInstance,
|
||||||
|
ProviderComputeInitializeResults,
|
||||||
ProviderInstance
|
ProviderInstance
|
||||||
} from '@oceanprotocol/lib'
|
} from '@oceanprotocol/lib'
|
||||||
|
import { da } from 'date-fns/locale'
|
||||||
import { AssetExtended } from 'src/@types/AssetExtended'
|
import { AssetExtended } from 'src/@types/AssetExtended'
|
||||||
import Web3 from 'web3'
|
import Web3 from 'web3'
|
||||||
|
import { getValidUntilTime } from './compute'
|
||||||
|
|
||||||
|
export async function initializeProviderForCompute(
|
||||||
|
dataset: AssetExtended,
|
||||||
|
algorithm: AssetExtended,
|
||||||
|
accountId: string,
|
||||||
|
computeEnv: ComputeEnvironment = null
|
||||||
|
): Promise<ProviderComputeInitializeResults> {
|
||||||
|
const computeAsset: ComputeAsset = {
|
||||||
|
documentId: dataset.id,
|
||||||
|
serviceId: dataset.services[0].id,
|
||||||
|
transferTxId: dataset.accessDetails.validOrderTx
|
||||||
|
}
|
||||||
|
const computeAlgo: ComputeAlgorithm = {
|
||||||
|
documentId: algorithm.id,
|
||||||
|
serviceId: algorithm.services[0].id,
|
||||||
|
transferTxId: algorithm.accessDetails.validOrderTx
|
||||||
|
}
|
||||||
|
|
||||||
|
const validUntil = getValidUntilTime(
|
||||||
|
computeEnv?.maxJobDuration,
|
||||||
|
dataset.services[0].timeout,
|
||||||
|
algorithm.services[0].timeout
|
||||||
|
)
|
||||||
|
|
||||||
|
return await ProviderInstance.initializeCompute(
|
||||||
|
[computeAsset],
|
||||||
|
computeAlgo,
|
||||||
|
computeEnv?.id,
|
||||||
|
validUntil,
|
||||||
|
dataset.services[0].serviceEndpoint,
|
||||||
|
accountId
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: Why do we have these one line functions ?!?!?!
|
// TODO: Why do we have these one line functions ?!?!?!
|
||||||
export async function getEncryptedFiles(
|
export async function getEncryptedFiles(
|
||||||
|
@ -10,7 +10,8 @@ import {
|
|||||||
ComputeEnvironment,
|
ComputeEnvironment,
|
||||||
LoggerInstance,
|
LoggerInstance,
|
||||||
ComputeAlgorithm,
|
ComputeAlgorithm,
|
||||||
ComputeOutput
|
ComputeOutput,
|
||||||
|
ProviderComputeInitializeResults
|
||||||
} from '@oceanprotocol/lib'
|
} from '@oceanprotocol/lib'
|
||||||
import { toast } from 'react-toastify'
|
import { toast } from 'react-toastify'
|
||||||
import Price from '@shared/Price'
|
import Price from '@shared/Price'
|
||||||
@ -27,9 +28,7 @@ import {
|
|||||||
isOrderable,
|
isOrderable,
|
||||||
getAlgorithmAssetSelectionList,
|
getAlgorithmAssetSelectionList,
|
||||||
getAlgorithmsForAsset,
|
getAlgorithmsForAsset,
|
||||||
getValidUntilTime,
|
getComputeEnviroment
|
||||||
getComputeEnviroment,
|
|
||||||
checkComputeResourcesValidity
|
|
||||||
} from '@utils/compute'
|
} from '@utils/compute'
|
||||||
import { AssetSelectionAsset } from '@shared/FormFields/AssetSelection'
|
import { AssetSelectionAsset } from '@shared/FormFields/AssetSelection'
|
||||||
import AlgorithmDatasetsListForCompute from './AlgorithmDatasetsListForCompute'
|
import AlgorithmDatasetsListForCompute from './AlgorithmDatasetsListForCompute'
|
||||||
@ -42,13 +41,14 @@ import { useAbortController } from '@hooks/useAbortController'
|
|||||||
import { getOrderPriceAndFees } from '@utils/accessDetailsAndPricing'
|
import { getOrderPriceAndFees } from '@utils/accessDetailsAndPricing'
|
||||||
import { OrderPriceAndFees } from 'src/@types/Price'
|
import { OrderPriceAndFees } from 'src/@types/Price'
|
||||||
import { buyDtFromPool } from '@utils/pool'
|
import { buyDtFromPool } from '@utils/pool'
|
||||||
import { order, reuseOrder } from '@utils/order'
|
import { handleComputeOrder, order, reuseOrder } from '@utils/order'
|
||||||
import { AssetExtended } from 'src/@types/AssetExtended'
|
import { AssetExtended } from 'src/@types/AssetExtended'
|
||||||
import { getComputeFeedback } from '@utils/feedback'
|
import { getComputeFeedback } from '@utils/feedback'
|
||||||
import { usePool } from '@context/Pool'
|
import { usePool } from '@context/Pool'
|
||||||
import { useMarketMetadata } from '@context/MarketMetadata'
|
import { useMarketMetadata } from '@context/MarketMetadata'
|
||||||
import { getPoolData } from '@context/Pool/_utils'
|
import { getPoolData } from '@context/Pool/_utils'
|
||||||
import { getDummyWeb3 } from '@utils/web3'
|
import { getDummyWeb3 } from '@utils/web3'
|
||||||
|
import { initializeProviderForCompute } from '@utils/provider'
|
||||||
|
|
||||||
export default function Compute({
|
export default function Compute({
|
||||||
asset,
|
asset,
|
||||||
@ -84,7 +84,7 @@ export default function Compute({
|
|||||||
const [validAlgorithmOrderTx, setValidAlgorithmOrderTx] = useState('')
|
const [validAlgorithmOrderTx, setValidAlgorithmOrderTx] = useState('')
|
||||||
|
|
||||||
const hasDatatoken = Number(dtBalance) >= 1
|
const hasDatatoken = Number(dtBalance) >= 1
|
||||||
const isMounted = useIsMounted()
|
// const isMounted = useIsMounted()
|
||||||
const { getOpcFeeForToken } = useMarketMetadata()
|
const { getOpcFeeForToken } = useMarketMetadata()
|
||||||
const { poolData } = usePool()
|
const { poolData } = usePool()
|
||||||
const newCancelToken = useCancelToken()
|
const newCancelToken = useCancelToken()
|
||||||
@ -92,7 +92,9 @@ export default function Compute({
|
|||||||
const [isAlgoConsumablePrice, setIsAlgoConsumablePrice] = useState(true)
|
const [isAlgoConsumablePrice, setIsAlgoConsumablePrice] = useState(true)
|
||||||
const [computeStatusText, setComputeStatusText] = useState('')
|
const [computeStatusText, setComputeStatusText] = useState('')
|
||||||
const [computeEnv, setComputeEnv] = useState<ComputeEnvironment>()
|
const [computeEnv, setComputeEnv] = useState<ComputeEnvironment>()
|
||||||
const [computeValidUntil, setComputeValidUntil] = useState<number>()
|
const [initializedProviderResponse, setInitializedProviderResponse] =
|
||||||
|
useState<ProviderComputeInitializeResults>()
|
||||||
|
// const [computeValidUntil, setComputeValidUntil] = useState<number>()
|
||||||
const [datasetOrderPriceAndFees, setDatasetOrderPriceAndFees] =
|
const [datasetOrderPriceAndFees, setDatasetOrderPriceAndFees] =
|
||||||
useState<OrderPriceAndFees>()
|
useState<OrderPriceAndFees>()
|
||||||
const [isRequestingDataseOrderPrice, setIsRequestingDataseOrderPrice] =
|
const [isRequestingDataseOrderPrice, setIsRequestingDataseOrderPrice] =
|
||||||
@ -101,7 +103,7 @@ export default function Compute({
|
|||||||
useState<OrderPriceAndFees>()
|
useState<OrderPriceAndFees>()
|
||||||
const [isRequestingAlgoOrderPrice, setIsRequestingAlgoOrderPrice] =
|
const [isRequestingAlgoOrderPrice, setIsRequestingAlgoOrderPrice] =
|
||||||
useState(false)
|
useState(false)
|
||||||
const [isProviderFeeValid, setIsProviderFeeValid] = useState(false)
|
// const [isProviderFeeValid, setIsProviderFeeValid] = useState(false)
|
||||||
const isComputeButtonDisabled =
|
const isComputeButtonDisabled =
|
||||||
isJobStarting === true ||
|
isJobStarting === true ||
|
||||||
file === null ||
|
file === null ||
|
||||||
@ -125,21 +127,35 @@ export default function Compute({
|
|||||||
async function initPriceAndFees() {
|
async function initPriceAndFees() {
|
||||||
const computeEnv = await getComputeEnviroment(asset)
|
const computeEnv = await getComputeEnviroment(asset)
|
||||||
setComputeEnv(computeEnv)
|
setComputeEnv(computeEnv)
|
||||||
setIsProviderFeeValid(
|
const initializedProvider = await initializeProviderForCompute(
|
||||||
await checkComputeResourcesValidity(
|
asset,
|
||||||
asset,
|
selectedAlgorithmAsset,
|
||||||
accountId,
|
accountId,
|
||||||
computeEnv?.maxJobDuration,
|
computeEnv
|
||||||
asset.services[0].timeout,
|
|
||||||
selectedAlgorithmAsset.services[0].timeout
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
const validUntil = getValidUntilTime(
|
setInitializedProviderResponse(initializedProvider)
|
||||||
computeEnv?.maxJobDuration,
|
// setIsProviderFeeValid(
|
||||||
asset.services[0].timeout,
|
// await checkComputeResourcesValidity(
|
||||||
selectedAlgorithmAsset.services[0].timeout
|
// asset,
|
||||||
)
|
// accountId,
|
||||||
setComputeValidUntil(validUntil)
|
// computeEnv?.maxJobDuration,
|
||||||
|
// asset.services[0].timeout,
|
||||||
|
// selectedAlgorithmAsset.services[0].timeout
|
||||||
|
// )
|
||||||
|
// )
|
||||||
|
// let datasetOrderTx = await checkComputeResourcesValidity(
|
||||||
|
// dataset,
|
||||||
|
// accountId,
|
||||||
|
// computeEnv?.maxJobDuration,
|
||||||
|
// asset.services[0].timeout,
|
||||||
|
// selectedAlgorithmAsset.services[0].timeout
|
||||||
|
// )
|
||||||
|
// const validUntil = getValidUntilTime(
|
||||||
|
// computeEnv?.maxJobDuration,
|
||||||
|
// asset.services[0].timeout,
|
||||||
|
// selectedAlgorithmAsset.services[0].timeout
|
||||||
|
// )
|
||||||
|
// setComputeValidUntil(validUntil)
|
||||||
if (
|
if (
|
||||||
asset?.accessDetails?.addressOrId !== ZERO_ADDRESS ||
|
asset?.accessDetails?.addressOrId !== ZERO_ADDRESS ||
|
||||||
asset?.accessDetails?.type !== 'free'
|
asset?.accessDetails?.type !== 'free'
|
||||||
@ -172,10 +188,8 @@ export default function Compute({
|
|||||||
asset,
|
asset,
|
||||||
ZERO_ADDRESS,
|
ZERO_ADDRESS,
|
||||||
poolParams,
|
poolParams,
|
||||||
computeEnv?.id,
|
initializedProvider.datasets[0].providerFee
|
||||||
validUntil
|
|
||||||
)
|
)
|
||||||
console.log('datasetPriceAndFees price and fees', datasetPriceAndFees)
|
|
||||||
if (!datasetPriceAndFees) {
|
if (!datasetPriceAndFees) {
|
||||||
setError('Error setting dataset price and fees!')
|
setError('Error setting dataset price and fees!')
|
||||||
toast.error('Error setting dataset price and fees!')
|
toast.error('Error setting dataset price and fees!')
|
||||||
@ -223,15 +237,13 @@ export default function Compute({
|
|||||||
selectedAlgorithmAsset,
|
selectedAlgorithmAsset,
|
||||||
ZERO_ADDRESS,
|
ZERO_ADDRESS,
|
||||||
algoPoolParams,
|
algoPoolParams,
|
||||||
computeEnv?.id,
|
initializedProvider.algorithm.providerFee
|
||||||
validUntil
|
|
||||||
)
|
)
|
||||||
if (!algorithmOrderPriceAndFees) {
|
if (!algorithmOrderPriceAndFees) {
|
||||||
setError('Error setting algorithm price and fees!')
|
setError('Error setting algorithm price and fees!')
|
||||||
toast.error('Error setting algorithm price and fees!')
|
toast.error('Error setting algorithm price and fees!')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
console.log('algo price and fees', algorithmOrderPriceAndFees)
|
|
||||||
setAlgoOrderPriceAndFees(algorithmOrderPriceAndFees)
|
setAlgoOrderPriceAndFees(algorithmOrderPriceAndFees)
|
||||||
setIsRequestingAlgoOrderPrice(false)
|
setIsRequestingAlgoOrderPrice(false)
|
||||||
}
|
}
|
||||||
@ -246,7 +258,6 @@ export default function Compute({
|
|||||||
}, [asset?.accessDetails])
|
}, [asset?.accessDetails])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
console.log('selcted algo', selectedAlgorithmAsset)
|
|
||||||
if (!selectedAlgorithmAsset?.accessDetails || !accountId) return
|
if (!selectedAlgorithmAsset?.accessDetails || !accountId) return
|
||||||
|
|
||||||
setIsConsumablePrice(selectedAlgorithmAsset?.accessDetails?.isPurchasable)
|
setIsConsumablePrice(selectedAlgorithmAsset?.accessDetails?.isPurchasable)
|
||||||
@ -311,153 +322,166 @@ export default function Compute({
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
let datasetOrderTx
|
const datasetOrderTx = await handleComputeOrder(
|
||||||
if (isOwned) {
|
web3,
|
||||||
datasetOrderTx = validOrderTx
|
asset,
|
||||||
LoggerInstance.log('[compute] Dataset owned txId:', validOrderTx)
|
datasetOrderPriceAndFees,
|
||||||
} else {
|
accountId,
|
||||||
try {
|
hasDatatoken,
|
||||||
if (!hasDatatoken && asset?.accessDetails.type === 'dynamic') {
|
initializedProviderResponse.datasets[0],
|
||||||
setComputeStatusText(
|
computeEnv.consumerAddress
|
||||||
getComputeFeedback(
|
)
|
||||||
asset.accessDetails.baseToken?.symbol,
|
// if (isOwned) {
|
||||||
asset.accessDetails.datatoken?.symbol,
|
// datasetOrderTx = validOrderTx
|
||||||
asset.metadata.type
|
// LoggerInstance.log('[compute] Dataset owned txId:', validOrderTx)
|
||||||
)[1]
|
// } else {
|
||||||
)
|
// try {
|
||||||
const tx = await buyDtFromPool(
|
// if (!hasDatatoken && asset?.accessDetails.type === 'dynamic') {
|
||||||
asset?.accessDetails,
|
// setComputeStatusText(
|
||||||
accountId,
|
// getComputeFeedback(
|
||||||
web3
|
// asset.accessDetails.baseToken?.symbol,
|
||||||
)
|
// asset.accessDetails.datatoken?.symbol,
|
||||||
LoggerInstance.log('[compute] Buy dataset dt from pool: ', tx)
|
// asset.metadata.type
|
||||||
if (!tx) {
|
// )[1]
|
||||||
toast.error('Failed to buy datatoken from pool!')
|
// )
|
||||||
return
|
// const tx = await buyDtFromPool(
|
||||||
}
|
// asset?.accessDetails,
|
||||||
}
|
// accountId,
|
||||||
LoggerInstance.log(
|
// web3
|
||||||
'dataset orderPriceAndFees: ',
|
// )
|
||||||
datasetOrderPriceAndFees
|
// LoggerInstance.log('[compute] Buy dataset dt from pool: ', tx)
|
||||||
)
|
// if (!tx) {
|
||||||
setComputeStatusText(
|
// toast.error('Failed to buy datatoken from pool!')
|
||||||
getComputeFeedback(
|
// return
|
||||||
asset.accessDetails.baseToken?.symbol,
|
// }
|
||||||
asset.accessDetails.datatoken?.symbol,
|
// }
|
||||||
asset.metadata.type
|
// LoggerInstance.log(
|
||||||
)[asset.accessDetails?.type === 'fixed' ? 3 : 2]
|
// 'dataset orderPriceAndFees: ',
|
||||||
)
|
// datasetOrderPriceAndFees
|
||||||
const orderTx = await order(
|
// )
|
||||||
web3,
|
// setComputeStatusText(
|
||||||
asset,
|
// getComputeFeedback(
|
||||||
datasetOrderPriceAndFees,
|
// asset.accessDetails.baseToken?.symbol,
|
||||||
accountId,
|
// asset.accessDetails.datatoken?.symbol,
|
||||||
computeEnv?.id,
|
// asset.metadata.type
|
||||||
computeValidUntil,
|
// )[asset.accessDetails?.type === 'fixed' ? 3 : 2]
|
||||||
computeEnv?.consumerAddress
|
// )
|
||||||
)
|
// const orderTx = await order(
|
||||||
if (!orderTx) {
|
// web3,
|
||||||
toast.error('Failed to order dataset asset!')
|
// asset,
|
||||||
return
|
// datasetOrderPriceAndFees,
|
||||||
}
|
// accountId, )
|
||||||
LoggerInstance.log(
|
// if (!orderTx) {
|
||||||
'[compute] Order dataset: ',
|
// toast.error('Failed to order dataset asset!')
|
||||||
orderTx.transactionHash
|
// return
|
||||||
)
|
// }
|
||||||
setIsOwned(true)
|
// LoggerInstance.log(
|
||||||
setValidOrderTx(orderTx.transactionHash)
|
// '[compute] Order dataset: ',
|
||||||
datasetOrderTx = orderTx.transactionHash
|
// orderTx.transactionHash
|
||||||
} catch (e) {
|
// )
|
||||||
LoggerInstance.log(e.message)
|
// setIsOwned(true)
|
||||||
toast.error('Failed to order dataset asset!')
|
// setValidOrderTx(orderTx.transactionHash)
|
||||||
return
|
// datasetOrderTx = orderTx.transactionHash
|
||||||
}
|
// } catch (e) {
|
||||||
}
|
// LoggerInstance.log(e.message)
|
||||||
|
// toast.error('Failed to order dataset asset!')
|
||||||
|
// return
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
let algorithmOrderTx
|
const algorithmOrderTx = await handleComputeOrder(
|
||||||
if (isAlgorithmOwned) {
|
web3,
|
||||||
algorithmOrderTx = validAlgorithmOrderTx
|
selectedAlgorithmAsset,
|
||||||
LoggerInstance.log(
|
datasetOrderPriceAndFees,
|
||||||
'[compute] Algorithm owned txId:',
|
accountId,
|
||||||
validAlgorithmOrderTx
|
hasDatatoken,
|
||||||
)
|
initializedProviderResponse.algorithm,
|
||||||
} else {
|
computeEnv.consumerAddress
|
||||||
try {
|
)
|
||||||
if (
|
|
||||||
!hasAlgoAssetDatatoken &&
|
|
||||||
selectedAlgorithmAsset?.accessDetails?.type === 'dynamic'
|
|
||||||
) {
|
|
||||||
setComputeStatusText(
|
|
||||||
getComputeFeedback(
|
|
||||||
selectedAlgorithmAsset.accessDetails.baseToken?.symbol,
|
|
||||||
selectedAlgorithmAsset.accessDetails.datatoken?.symbol,
|
|
||||||
selectedAlgorithmAsset.metadata.type
|
|
||||||
)[1]
|
|
||||||
)
|
|
||||||
const tx = await buyDtFromPool(
|
|
||||||
selectedAlgorithmAsset?.accessDetails,
|
|
||||||
accountId,
|
|
||||||
web3
|
|
||||||
)
|
|
||||||
LoggerInstance.log('[compute] Buy algorithm dt from pool: ', tx)
|
|
||||||
if (!tx) {
|
|
||||||
toast.error('Failed to buy datatoken from pool!')
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
setComputeStatusText(
|
|
||||||
getComputeFeedback(
|
|
||||||
selectedAlgorithmAsset.accessDetails.baseToken?.symbol,
|
|
||||||
selectedAlgorithmAsset.accessDetails.datatoken?.symbol,
|
|
||||||
selectedAlgorithmAsset.metadata.type
|
|
||||||
)[selectedAlgorithmAsset.accessDetails?.type === 'fixed' ? 3 : 2]
|
|
||||||
)
|
|
||||||
const orderTx = await order(
|
|
||||||
web3,
|
|
||||||
selectedAlgorithmAsset,
|
|
||||||
algoOrderPriceAndFees,
|
|
||||||
accountId,
|
|
||||||
computeEnv?.id,
|
|
||||||
computeValidUntil,
|
|
||||||
computeEnv?.consumerAddress
|
|
||||||
)
|
|
||||||
if (!orderTx) {
|
|
||||||
toast.error('Failed to order algorithm asset!')
|
|
||||||
return
|
|
||||||
}
|
|
||||||
LoggerInstance.log(
|
|
||||||
'[compute] Order algorithm: ',
|
|
||||||
orderTx.transactionHash
|
|
||||||
)
|
|
||||||
setIsAlgorithmOwned(true)
|
|
||||||
setValidAlgorithmOrderTx(orderTx.transactionHash)
|
|
||||||
algorithmOrderTx = orderTx.transactionHash
|
|
||||||
} catch (e) {
|
|
||||||
LoggerInstance.log(e.message)
|
|
||||||
toast.error('Failed to order algorithm asset!')
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isOwned && !isProviderFeeValid) {
|
// if (isAlgorithmOwned) {
|
||||||
const reuseOrderTx = await reuseOrder(
|
// algorithmOrderTx = validAlgorithmOrderTx
|
||||||
web3,
|
// LoggerInstance.log(
|
||||||
asset,
|
// '[compute] Algorithm owned txId:',
|
||||||
accountId,
|
// validAlgorithmOrderTx
|
||||||
validOrderTx,
|
// )
|
||||||
computeEnv?.id,
|
// } else {
|
||||||
computeValidUntil
|
// try {
|
||||||
)
|
// if (
|
||||||
if (!reuseOrderTx) {
|
// !hasAlgoAssetDatatoken &&
|
||||||
toast.error('Failed to pay provider fees!')
|
// selectedAlgorithmAsset?.accessDetails?.type === 'dynamic'
|
||||||
return
|
// ) {
|
||||||
}
|
// setComputeStatusText(
|
||||||
LoggerInstance.log(
|
// getComputeFeedback(
|
||||||
'[compute] Reused order: ',
|
// selectedAlgorithmAsset.accessDetails.baseToken?.symbol,
|
||||||
reuseOrderTx.transactionHash
|
// selectedAlgorithmAsset.accessDetails.datatoken?.symbol,
|
||||||
)
|
// selectedAlgorithmAsset.metadata.type
|
||||||
datasetOrderTx = reuseOrderTx.transactionHash
|
// )[1]
|
||||||
}
|
// )
|
||||||
|
// const tx = await buyDtFromPool(
|
||||||
|
// selectedAlgorithmAsset?.accessDetails,
|
||||||
|
// accountId,
|
||||||
|
// web3
|
||||||
|
// )
|
||||||
|
// LoggerInstance.log('[compute] Buy algorithm dt from pool: ', tx)
|
||||||
|
// if (!tx) {
|
||||||
|
// toast.error('Failed to buy datatoken from pool!')
|
||||||
|
// return
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// setComputeStatusText(
|
||||||
|
// getComputeFeedback(
|
||||||
|
// selectedAlgorithmAsset.accessDetails.baseToken?.symbol,
|
||||||
|
// selectedAlgorithmAsset.accessDetails.datatoken?.symbol,
|
||||||
|
// selectedAlgorithmAsset.metadata.type
|
||||||
|
// )[selectedAlgorithmAsset.accessDetails?.type === 'fixed' ? 3 : 2]
|
||||||
|
// )
|
||||||
|
// const orderTx = await order(
|
||||||
|
// web3,
|
||||||
|
// selectedAlgorithmAsset,
|
||||||
|
// algoOrderPriceAndFees,
|
||||||
|
// accountId,
|
||||||
|
// computeEnv?.id,
|
||||||
|
// computeValidUntil,
|
||||||
|
// computeEnv?.consumerAddress
|
||||||
|
// )
|
||||||
|
// if (!orderTx) {
|
||||||
|
// toast.error('Failed to order algorithm asset!')
|
||||||
|
// return
|
||||||
|
// }
|
||||||
|
// LoggerInstance.log(
|
||||||
|
// '[compute] Order algorithm: ',
|
||||||
|
// orderTx.transactionHash
|
||||||
|
// )
|
||||||
|
// setIsAlgorithmOwned(true)
|
||||||
|
// setValidAlgorithmOrderTx(orderTx.transactionHash)
|
||||||
|
// algorithmOrderTx = orderTx.transactionHash
|
||||||
|
// } catch (e) {
|
||||||
|
// LoggerInstance.log(e.message)
|
||||||
|
// toast.error('Failed to order algorithm asset!')
|
||||||
|
// return
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// if (isOwned && !isProviderFeeValid) {
|
||||||
|
// const reuseOrderTx = await reuseOrder(
|
||||||
|
// web3,
|
||||||
|
// asset,
|
||||||
|
// accountId,
|
||||||
|
// validOrderTx,
|
||||||
|
// computeEnv?.id,
|
||||||
|
// computeValidUntil
|
||||||
|
// )
|
||||||
|
// if (!reuseOrderTx) {
|
||||||
|
// toast.error('Failed to pay provider fees!')
|
||||||
|
// return
|
||||||
|
// }
|
||||||
|
// LoggerInstance.log(
|
||||||
|
// '[compute] Reused order: ',
|
||||||
|
// reuseOrderTx.transactionHash
|
||||||
|
// )
|
||||||
|
// datasetOrderTx = reuseOrderTx.transactionHash
|
||||||
|
// }
|
||||||
|
|
||||||
LoggerInstance.log('[compute] Starting compute job.')
|
LoggerInstance.log('[compute] Starting compute job.')
|
||||||
const computeAsset: ComputeAsset = {
|
const computeAsset: ComputeAsset = {
|
||||||
|
Loading…
Reference in New Issue
Block a user