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

Fix compute basetoken issue (#1829)

* fix lint

* add dynamic provider fees

* fixes

* cleanup and more fixes

* bump oceanlib to 2.6.0
This commit is contained in:
Bogdan Fazakas 2023-01-10 10:39:03 +02:00 committed by GitHub
parent 5ef0594927
commit cde92c6c46
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 138 additions and 110 deletions

View File

@ -30,44 +30,47 @@
{
"name": "files",
"label": "File",
"prominentHelp": false,
"prominentHelp": false,
"type": "tabs",
"fields": [{
"value": "ipfs",
"title": "IPFS",
"label": "CID",
"placeholder": "e.g. bafkreidgvpkjawlxz6sffxzwgooowe5yt7i6wsyg236mfoks77nywkptdq",
"help": "This CID will be stored encrypted after publishing.",
"computeHelp": "For a compute dataset, your file should match the file type required by the algorithm, and should not exceed 1 GB in file size. ",
"prominentHelp": true,
"type": "files",
"required": true
},
{
"value": "arweave",
"title": "Arweave",
"label": "Transaction ID",
"placeholder": "e.g. DBRCL94j3QqdPaUtt4VWRen8rZfJZBb7Ey40iMpXfhtd",
"help": "This Transaction ID will be stored encrypted after publishing.",
"computeHelp": "For a compute dataset, your file should match the file type required by the algorithm, and should not exceed 1 GB in file size. ",
"prominentHelp": true,
"type": "files",
"required": true
},
{
"value": "url",
"title": "URL",
"label": "File",
"placeholder": "e.g. https://file.com/file.json",
"help": "This URL will be stored encrypted after publishing. **Please make sure that the endpoint is accessible over the internet and is not protected by a firewall or by credentials.**",
"computeHelp": "For a compute dataset, your file should match the file type required by the algorithm, and should not exceed 1 GB in file size. ",
"prominentHelp": true,
"type": "files",
"required": true
}],
"fields": [
{
"value": "ipfs",
"title": "IPFS",
"label": "CID",
"placeholder": "e.g. bafkreidgvpkjawlxz6sffxzwgooowe5yt7i6wsyg236mfoks77nywkptdq",
"help": "This CID will be stored encrypted after publishing.",
"computeHelp": "For a compute dataset, your file should match the file type required by the algorithm, and should not exceed 1 GB in file size. ",
"prominentHelp": true,
"type": "files",
"required": true
},
{
"value": "arweave",
"title": "Arweave",
"label": "Transaction ID",
"placeholder": "e.g. DBRCL94j3QqdPaUtt4VWRen8rZfJZBb7Ey40iMpXfhtd",
"help": "This Transaction ID will be stored encrypted after publishing.",
"computeHelp": "For a compute dataset, your file should match the file type required by the algorithm, and should not exceed 1 GB in file size. ",
"prominentHelp": true,
"type": "files",
"required": true
},
{
"value": "url",
"title": "URL",
"label": "File",
"placeholder": "e.g. https://file.com/file.json",
"help": "This URL will be stored encrypted after publishing. **Please make sure that the endpoint is accessible over the internet and is not protected by a firewall or by credentials.**",
"computeHelp": "For a compute dataset, your file should match the file type required by the algorithm, and should not exceed 1 GB in file size. ",
"prominentHelp": true,
"type": "files",
"required": true
}
],
"sortOptions": false,
"required": true
},{
},
{
"name": "links",
"label": "Sample file",
"prominentHelp": false,
@ -83,7 +86,8 @@
"prominentHelp": true,
"type": "files",
"required": false
}],
}
],
"required": false
},

View File

@ -104,60 +104,64 @@
{
"name": "files",
"label": "File",
"prominentHelp": false,
"prominentHelp": false,
"type": "tabs",
"fields": [{
"value": "ipfs",
"title": "IPFS",
"label": "CID",
"placeholder": "e.g. bafkreidgvpkjawlxz6sffxzwgooowe5yt7i6wsyg236mfoks77nywkptdq",
"help": "This CID will be stored encrypted after publishing.",
"computeHelp": "For a compute dataset, your file should match the file type required by the algorithm, and should not exceed 1 GB in file size. ",
"prominentHelp": true,
"type": "files",
"required": true
},
{
"value": "arweave",
"title": "Arweave",
"label": "Transaction ID",
"placeholder": "e.g. DBRCL94j3QqdPaUtt4VWRen8rZfJZBb7Ey40iMpXfhtd",
"help": "This Transaction ID will be stored encrypted after publishing.",
"computeHelp": "For a compute dataset, your file should match the file type required by the algorithm, and should not exceed 1 GB in file size. ",
"prominentHelp": true,
"type": "files",
"required": true
},
{
"value": "url",
"title": "URL",
"label": "File",
"placeholder": "e.g. https://file.com/file.json",
"help": "This URL will be stored encrypted after publishing. **Please make sure that the endpoint is accessible over the internet and is not protected by a firewall or by credentials.**",
"computeHelp": "For a compute dataset, your file should match the file type required by the algorithm, and should not exceed 1 GB in file size. ",
"prominentHelp": true,
"type": "files",
"required": true
}],
"fields": [
{
"value": "ipfs",
"title": "IPFS",
"label": "CID",
"placeholder": "e.g. bafkreidgvpkjawlxz6sffxzwgooowe5yt7i6wsyg236mfoks77nywkptdq",
"help": "This CID will be stored encrypted after publishing.",
"computeHelp": "For a compute dataset, your file should match the file type required by the algorithm, and should not exceed 1 GB in file size. ",
"prominentHelp": true,
"type": "files",
"required": true
},
{
"value": "arweave",
"title": "Arweave",
"label": "Transaction ID",
"placeholder": "e.g. DBRCL94j3QqdPaUtt4VWRen8rZfJZBb7Ey40iMpXfhtd",
"help": "This Transaction ID will be stored encrypted after publishing.",
"computeHelp": "For a compute dataset, your file should match the file type required by the algorithm, and should not exceed 1 GB in file size. ",
"prominentHelp": true,
"type": "files",
"required": true
},
{
"value": "url",
"title": "URL",
"label": "File",
"placeholder": "e.g. https://file.com/file.json",
"help": "This URL will be stored encrypted after publishing. **Please make sure that the endpoint is accessible over the internet and is not protected by a firewall or by credentials.**",
"computeHelp": "For a compute dataset, your file should match the file type required by the algorithm, and should not exceed 1 GB in file size. ",
"prominentHelp": true,
"type": "files",
"required": true
}
],
"sortOptions": false,
"required": true
},{
},
{
"name": "links",
"label": "Sample file",
"prominentHelp": false,
"type": "tabs",
"fields": [
{
"value": "url",
"title": "URL",
"label": "File",
"placeholder": "e.g. https://file.com/file.json",
"help": "This URL will be stored encrypted after publishing. **Please make sure that the endpoint is accessible over the internet and is not protected by a firewall or by credentials.**",
"computeHelp": "For a compute dataset, your file should match the file type required by the algorithm, and should not exceed 1 GB in file size. ",
"prominentHelp": true,
"type": "files",
"required": false
}],
"value": "url",
"title": "URL",
"label": "File",
"placeholder": "e.g. https://file.com/file.json",
"help": "This URL will be stored encrypted after publishing. **Please make sure that the endpoint is accessible over the internet and is not protected by a firewall or by credentials.**",
"computeHelp": "For a compute dataset, your file should match the file type required by the algorithm, and should not exceed 1 GB in file size. ",
"prominentHelp": true,
"type": "files",
"required": false
}
],
"required": false
},
{

32
package-lock.json generated
View File

@ -13,7 +13,7 @@
"@coingecko/cryptoformat": "^0.5.4",
"@loadable/component": "^5.15.2",
"@oceanprotocol/art": "^3.2.0",
"@oceanprotocol/lib": "^2.5.2",
"@oceanprotocol/lib": "^2.6.0",
"@oceanprotocol/typographies": "^0.1.0",
"@oceanprotocol/use-dark-mode": "^2.4.3",
"@tippyjs/react": "^4.2.6",
@ -4591,18 +4591,18 @@
"integrity": "sha512-I6xoADZpP/8EyN3VWZ+dLYv24DbJj3xzmSDcYv0FolXeAUF3FluzminL5AgQtAaoyUtlHl1D3ij1B++KupWcQQ=="
},
"node_modules/@oceanprotocol/lib": {
"version": "2.5.2",
"resolved": "https://registry.npmjs.org/@oceanprotocol/lib/-/lib-2.5.2.tgz",
"integrity": "sha512-hLNTS6go1GhpSJt7un1VPb/6XNNYSwGpYPX/O1E5q2XCRWjaWYodzqwxBcgQKw2ihSQmaH9JsDsFLZiIKqKRLA==",
"version": "2.6.0",
"resolved": "https://registry.npmjs.org/@oceanprotocol/lib/-/lib-2.6.0.tgz",
"integrity": "sha512-UMWOdJksJO43wzsmyidOjTyGtARw9OKGde6xbunNuRJDLmeYui4OZ0KTwA5yWBSibsqWk4TVAJgXrxW096NJ5g==",
"dependencies": {
"@oceanprotocol/contracts": "^1.1.8",
"bignumber.js": "^9.1.0",
"cross-fetch": "^3.1.5",
"crypto-js": "^4.1.1",
"decimal.js": "^10.4.1",
"web3": "^1.8.0",
"web3-core": "^1.8.0",
"web3-eth-contract": "^1.8.0"
"web3": "^1.8.1",
"web3-core": "^1.8.1",
"web3-eth-contract": "^1.8.1"
},
"peerDependencies": {
"web3": "^1.8.0"
@ -50186,18 +50186,17 @@
"integrity": "sha512-I6xoADZpP/8EyN3VWZ+dLYv24DbJj3xzmSDcYv0FolXeAUF3FluzminL5AgQtAaoyUtlHl1D3ij1B++KupWcQQ=="
},
"@oceanprotocol/lib": {
"version": "2.5.2",
"resolved": "https://registry.npmjs.org/@oceanprotocol/lib/-/lib-2.5.2.tgz",
"integrity": "sha512-hLNTS6go1GhpSJt7un1VPb/6XNNYSwGpYPX/O1E5q2XCRWjaWYodzqwxBcgQKw2ihSQmaH9JsDsFLZiIKqKRLA==",
"version": "2.6.0",
"resolved": "https://registry.npmjs.org/@oceanprotocol/lib/-/lib-2.6.0.tgz",
"integrity": "sha512-UMWOdJksJO43wzsmyidOjTyGtARw9OKGde6xbunNuRJDLmeYui4OZ0KTwA5yWBSibsqWk4TVAJgXrxW096NJ5g==",
"requires": {
"@oceanprotocol/contracts": "^1.1.8",
"bignumber.js": "^9.1.0",
"cross-fetch": "^3.1.5",
"crypto-js": "^4.1.1",
"decimal.js": "^10.4.1",
"web3": "^1.8.0",
"web3-core": "^1.8.0",
"web3-eth-contract": "^1.8.0"
"web3-core": "^1.8.1",
"web3-eth-contract": "^1.8.1"
}
},
"@oceanprotocol/typographies": {
@ -50256,7 +50255,6 @@
"integrity": "sha512-rmVKYEsKzurfRU0xJz+iHelbi1LGlihIWZ7Qvmb/CBz1EkhL7nOkW4SVXmG2dA5Ce0si2gr88i6q4eBOMRNJ1w==",
"dev": true,
"requires": {
"@oclif/config": "^1.18.2",
"@oclif/errors": "^1.3.5",
"@oclif/help": "^1.0.1",
"@oclif/parser": "^3.8.6",
@ -61274,7 +61272,7 @@
"git-url-parse": "11.6.0",
"glob": "8.0.1",
"global-agent": "3.0.0",
"graphql": "15.8.0",
"graphql": "14.0.2 - 14.2.0 || ^14.3.1 || ^15.0.0",
"graphql-tag": "2.12.6",
"listr": "0.14.3",
"lodash.identity": "3.0.0",
@ -61515,7 +61513,7 @@
"cosmiconfig": "^7.0.1",
"dotenv": "^16.0.0",
"glob": "^8.0.0",
"graphql": "15.8.0",
"graphql": "14.0.2 - 14.2.0 || ^14.3.1 || ^15.0.0",
"graphql-tag": "^2.10.1",
"lodash.debounce": "^4.0.8",
"lodash.merge": "^4.6.1",
@ -74394,7 +74392,6 @@
"integrity": "sha512-uJx9y/1NIqoYTp6ZW1osJ7U5ZrXGAJbOQ/Qzl05BdGYvN1S7Qmbzid6xOirgK0EIT0pJKEEh1s8qbassYZe4cw==",
"peer": true,
"requires": {
"@babel/core": "^7.14.0",
"@babel/plugin-proposal-async-generator-functions": "^7.0.0",
"@babel/plugin-proposal-class-properties": "^7.0.0",
"@babel/plugin-proposal-export-default-from": "^7.0.0",
@ -74449,7 +74446,6 @@
"integrity": "sha512-Ogst/M6ujYrl/+9mpEWqE3zF7l2mTuftDTy3L8wZYwX1pWUQWQpfU1aJBeWiLxt1XlIq+uriRjKzKoRoIK57EA==",
"peer": true,
"requires": {
"@babel/core": "^7.14.0",
"babel-preset-fbjs": "^3.4.0",
"hermes-parser": "0.8.0",
"metro-babel-transformer": "0.72.3",

View File

@ -26,7 +26,7 @@
"@coingecko/cryptoformat": "^0.5.4",
"@loadable/component": "^5.15.2",
"@oceanprotocol/art": "^3.2.0",
"@oceanprotocol/lib": "^2.5.2",
"@oceanprotocol/lib": "^2.6.0",
"@oceanprotocol/typographies": "^0.1.0",
"@oceanprotocol/use-dark-mode": "^2.4.3",
"@tippyjs/react": "^4.2.6",

View File

@ -33,6 +33,7 @@ export default function FormStartCompute({
hasDatatokenSelectedComputeAsset,
datasetSymbol,
algorithmSymbol,
providerFeesSymbol,
dtSymbolSelectedComputeAsset,
dtBalanceSelectedComputeAsset,
selectedComputeAssetType,
@ -61,6 +62,7 @@ export default function FormStartCompute({
hasDatatokenSelectedComputeAsset?: boolean
datasetSymbol?: string
algorithmSymbol?: string
providerFeesSymbol?: string
dtSymbolSelectedComputeAsset?: string
dtBalanceSelectedComputeAsset?: string
selectedComputeAssetType?: string
@ -145,7 +147,7 @@ export default function FormStartCompute({
? new Decimal(providerFeeAmount).toDecimalPlaces(MAX_DECIMALS)
: new Decimal(0)
if (algorithmSymbol === 'OCEAN') {
if (algorithmSymbol === providerFeesSymbol) {
let sum = providerFees.add(priceAlgo)
totalPrices.push({
value: sum.toDecimalPlaces(MAX_DECIMALS).toString(),
@ -161,7 +163,7 @@ export default function FormStartCompute({
})
}
} else {
if (datasetSymbol === 'OCEAN') {
if (datasetSymbol === providerFeesSymbol) {
const sum = providerFees.add(priceDataset)
totalPrices.push({
value: sum.toDecimalPlaces(MAX_DECIMALS).toString(),
@ -179,7 +181,7 @@ export default function FormStartCompute({
})
totalPrices.push({
value: providerFees.toDecimalPlaces(MAX_DECIMALS).toString(),
symbol: 'OCEAN'
symbol: providerFeesSymbol
})
} else {
totalPrices.push({
@ -188,7 +190,7 @@ export default function FormStartCompute({
})
totalPrices.push({
value: providerFees.toDecimalPlaces(MAX_DECIMALS).toString(),
symbol: 'OCEAN'
symbol: providerFeesSymbol
})
totalPrices.push({
value: priceAlgo.toDecimalPlaces(MAX_DECIMALS).toString(),
@ -211,7 +213,8 @@ export default function FormStartCompute({
datasetOrderPrice,
algoOrderPrice,
algorithmSymbol,
datasetSymbol
datasetSymbol,
providerFeesSymbol
])
useEffect(() => {
@ -263,6 +266,7 @@ export default function FormStartCompute({
datasetOrderPrice={datasetOrderPrice}
algoOrderPrice={algoOrderPrice}
providerFeeAmount={providerFeeAmount}
providerFeesSymbol={providerFeesSymbol}
validUntil={validUntil}
totalPrices={totalPrices}
/>

View File

@ -20,6 +20,7 @@ interface PriceOutputProps {
datasetOrderPrice?: string
algoOrderPrice?: string
providerFeeAmount?: string
providerFeesSymbol?: string
validUntil?: string
totalPrices?: totalPriceMap[]
}
@ -84,6 +85,7 @@ export default function PriceOutput({
datasetOrderPrice,
algoOrderPrice,
providerFeeAmount,
providerFeesSymbol,
validUntil,
totalPrices
}: PriceOutputProps): ReactElement {
@ -134,7 +136,7 @@ export default function PriceOutput({
<Row
price={providerFeeAmount} // initializeCompute.provider fee amount
timeout={`${validUntil} seconds`} // valid until value
symbol={'OCEAN'} // we assume that provider fees will always be in OCEAN token
symbol={providerFeesSymbol} // we assume that provider fees will always be in OCEAN token
sign="+"
type="C2D RESOURCES"
/>

View File

@ -12,7 +12,8 @@ import {
ComputeAlgorithm,
ComputeOutput,
ProviderComputeInitializeResults,
unitsToAmount
unitsToAmount,
minAbi
} from '@oceanprotocol/lib'
import { toast } from 'react-toastify'
import Price from '@shared/Price'
@ -61,7 +62,7 @@ export default function Compute({
fileIsLoading?: boolean
consumableFeedback?: string
}): ReactElement {
const { accountId, web3, isSupportedOceanNetwork } = useWeb3()
const { accountId, web3, isSupportedOceanNetwork, networkId } = useWeb3()
const { chainIds } = useUserPreferences()
const { isAssetNetwork } = useAsset()
@ -90,6 +91,7 @@ export default function Compute({
const [initializedProviderResponse, setInitializedProviderResponse] =
useState<ProviderComputeInitializeResults>()
const [providerFeeAmount, setProviderFeeAmount] = useState<string>('0')
const [providerFeesSymbol, setProviderFeesSymbol] = useState<string>('OCEAN')
const [computeValidUntil, setComputeValidUntil] = useState<string>('0')
const [datasetOrderPriceAndFees, setDatasetOrderPriceAndFees] =
useState<OrderPriceAndFees>()
@ -160,6 +162,18 @@ export default function Compute({
setProviderFeeAmount(feeAmount)
const datatoken = new Datatoken(
await getDummyWeb3(asset?.chainId),
null,
null,
minAbi
)
setProviderFeesSymbol(
await datatoken.getSymbol(
initializedProvider?.datasets?.[0]?.providerFee?.providerFeeToken
)
)
const computeDuration = (
parseInt(initializedProvider?.datasets?.[0]?.providerFee?.validUntil) -
Math.floor(Date.now() / 1000)
@ -466,11 +480,15 @@ export default function Compute({
assetTimeout={secondsToString(asset?.services[0].timeout)}
hasPreviousOrderSelectedComputeAsset={!!validAlgorithmOrderTx}
hasDatatokenSelectedComputeAsset={hasAlgoAssetDatatoken}
datasetSymbol={asset?.accessDetails?.baseToken?.symbol || 'OCEAN'}
datasetSymbol={
asset?.accessDetails?.baseToken?.symbol ||
(asset?.chainId === 137 ? 'mOCEAN' : 'OCEAN')
}
algorithmSymbol={
selectedAlgorithmAsset?.accessDetails?.baseToken?.symbol ||
'OCEAN'
(selectedAlgorithmAsset?.chainId === 137 ? 'mOCEAN' : 'OCEAN')
}
providerFeesSymbol={providerFeesSymbol}
dtSymbolSelectedComputeAsset={
selectedAlgorithmAsset?.datatokens[0]?.symbol
}