mirror of
https://github.com/oceanprotocol/market.git
synced 2024-12-02 05:57:29 +01:00
fix provider fee display
This commit is contained in:
parent
ed3d736faf
commit
2c288f2591
@ -12,7 +12,8 @@ import {
|
|||||||
Asset,
|
Asset,
|
||||||
LoggerInstance,
|
LoggerInstance,
|
||||||
ProviderFees,
|
ProviderFees,
|
||||||
ProviderInstance
|
ProviderInstance,
|
||||||
|
unitsToAmount
|
||||||
} from '@oceanprotocol/lib'
|
} from '@oceanprotocol/lib'
|
||||||
import { AssetExtended } from 'src/@types/AssetExtended'
|
import { AssetExtended } from 'src/@types/AssetExtended'
|
||||||
import { calcInGivenOut } from './pool'
|
import { calcInGivenOut } from './pool'
|
||||||
@ -20,6 +21,7 @@ import { getFixedBuyPrice } from './fixedRateExchange'
|
|||||||
import { AccessDetails, OrderPriceAndFees } from 'src/@types/Price'
|
import { AccessDetails, OrderPriceAndFees } from 'src/@types/Price'
|
||||||
import Decimal from 'decimal.js'
|
import Decimal from 'decimal.js'
|
||||||
import { consumeMarketOrderFee } from '../../app.config'
|
import { consumeMarketOrderFee } from '../../app.config'
|
||||||
|
import Web3 from 'web3'
|
||||||
|
|
||||||
const tokensPriceQuery = gql`
|
const tokensPriceQuery = gql`
|
||||||
query TokensPriceQuery($datatokenIds: [ID!], $account: String) {
|
query TokensPriceQuery($datatokenIds: [ID!], $account: String) {
|
||||||
@ -255,6 +257,7 @@ function getAccessDetailsFromTokenPrice(
|
|||||||
* @return {Promise<OrdePriceAndFee>}
|
* @return {Promise<OrdePriceAndFee>}
|
||||||
*/
|
*/
|
||||||
export async function getOrderPriceAndFees(
|
export async function getOrderPriceAndFees(
|
||||||
|
web3: Web3,
|
||||||
asset: AssetExtended,
|
asset: AssetExtended,
|
||||||
accountId?: string,
|
accountId?: string,
|
||||||
paramsForPool?: CalcInGivenOutParams,
|
paramsForPool?: CalcInGivenOutParams,
|
||||||
@ -316,7 +319,15 @@ export async function getOrderPriceAndFees(
|
|||||||
orderPriceAndFee.price = new Decimal(+orderPriceAndFee.price || 0)
|
orderPriceAndFee.price = new Decimal(+orderPriceAndFee.price || 0)
|
||||||
.add(new Decimal(+orderPriceAndFee?.consumeMarketOrderFee || 0))
|
.add(new Decimal(+orderPriceAndFee?.consumeMarketOrderFee || 0))
|
||||||
.add(new Decimal(+orderPriceAndFee?.publisherMarketOrderFee || 0))
|
.add(new Decimal(+orderPriceAndFee?.publisherMarketOrderFee || 0))
|
||||||
.add(new Decimal(+orderPriceAndFee?.providerFee?.providerFeeAmount || 0))
|
.add(
|
||||||
|
new Decimal(
|
||||||
|
(await unitsToAmount(
|
||||||
|
web3,
|
||||||
|
orderPriceAndFee?.providerFee?.providerFeeToken,
|
||||||
|
orderPriceAndFee?.providerFee?.providerFeeAmount.toString()
|
||||||
|
)) || 0
|
||||||
|
)
|
||||||
|
)
|
||||||
.toString()
|
.toString()
|
||||||
return orderPriceAndFee
|
return orderPriceAndFee
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,8 @@ import {
|
|||||||
OrderParams,
|
OrderParams,
|
||||||
ProviderComputeInitialize,
|
ProviderComputeInitialize,
|
||||||
ProviderFees,
|
ProviderFees,
|
||||||
ProviderInstance
|
ProviderInstance,
|
||||||
|
unitsToAmount
|
||||||
} from '@oceanprotocol/lib'
|
} from '@oceanprotocol/lib'
|
||||||
import { AssetExtended } from 'src/@types/AssetExtended'
|
import { AssetExtended } from 'src/@types/AssetExtended'
|
||||||
import Web3 from 'web3'
|
import Web3 from 'web3'
|
||||||
@ -52,10 +53,17 @@ export async function order(
|
|||||||
asset.services[0].serviceEndpoint
|
asset.services[0].serviceEndpoint
|
||||||
))
|
))
|
||||||
|
|
||||||
|
const providerFeesSanitized = providerFees || initializeData.providerFee
|
||||||
|
providerFeesSanitized.providerFeeAmount = await unitsToAmount(
|
||||||
|
web3,
|
||||||
|
providerFeesSanitized.providerFeeToken,
|
||||||
|
providerFeesSanitized.providerFeeAmount.toString()
|
||||||
|
)
|
||||||
|
|
||||||
const orderParams = {
|
const orderParams = {
|
||||||
consumer: computeConsumerAddress || accountId,
|
consumer: computeConsumerAddress || accountId,
|
||||||
serviceIndex: 0,
|
serviceIndex: 0,
|
||||||
_providerFee: providerFees || initializeData.providerFee,
|
_providerFee: providerFeesSanitized,
|
||||||
_consumeMarketFee: {
|
_consumeMarketFee: {
|
||||||
consumeMarketFeeAddress: marketFeeAddress,
|
consumeMarketFeeAddress: marketFeeAddress,
|
||||||
consumeMarketFeeAmount: consumeMarketOrderFee,
|
consumeMarketFeeAmount: consumeMarketOrderFee,
|
||||||
@ -86,6 +94,8 @@ export async function order(
|
|||||||
swapMarketFee: consumeMarketFixedSwapFee,
|
swapMarketFee: consumeMarketFixedSwapFee,
|
||||||
marketFeeAddress
|
marketFeeAddress
|
||||||
} as FreOrderParams
|
} as FreOrderParams
|
||||||
|
console.log('freParams', freParams)
|
||||||
|
console.log('orderParams', orderParams)
|
||||||
const tx = await datatoken.buyFromFreAndOrder(
|
const tx = await datatoken.buyFromFreAndOrder(
|
||||||
asset.accessDetails.datatoken.address,
|
asset.accessDetails.datatoken.address,
|
||||||
accountId,
|
accountId,
|
||||||
@ -153,10 +163,15 @@ export async function reuseOrder(
|
|||||||
web3,
|
web3,
|
||||||
accountId,
|
accountId,
|
||||||
providerFees.providerFeeToken ||
|
providerFees.providerFeeToken ||
|
||||||
initializeData.providerFee.providerFeeAmount,
|
|
||||||
asset.accessDetails.datatoken.address,
|
|
||||||
providerFees.providerFeeAmount ||
|
|
||||||
initializeData.providerFee.providerFeeToken,
|
initializeData.providerFee.providerFeeToken,
|
||||||
|
asset.accessDetails.datatoken.address,
|
||||||
|
await unitsToAmount(
|
||||||
|
web3,
|
||||||
|
providerFees.providerFeeToken ||
|
||||||
|
initializeData.providerFee.providerFeeToken,
|
||||||
|
providerFees.providerFeeAmount ||
|
||||||
|
initializeData.providerFee.providerFeeAmount
|
||||||
|
),
|
||||||
false
|
false
|
||||||
)
|
)
|
||||||
if (!txApprove) {
|
if (!txApprove) {
|
||||||
|
@ -176,6 +176,7 @@ export default function Compute({
|
|||||||
}
|
}
|
||||||
: null
|
: null
|
||||||
const datasetPriceAndFees = await getOrderPriceAndFees(
|
const datasetPriceAndFees = await getOrderPriceAndFees(
|
||||||
|
web3,
|
||||||
asset,
|
asset,
|
||||||
ZERO_ADDRESS,
|
ZERO_ADDRESS,
|
||||||
poolParams,
|
poolParams,
|
||||||
@ -223,6 +224,7 @@ export default function Compute({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
const algorithmOrderPriceAndFees = await getOrderPriceAndFees(
|
const algorithmOrderPriceAndFees = await getOrderPriceAndFees(
|
||||||
|
web3,
|
||||||
selectedAlgorithmAsset,
|
selectedAlgorithmAsset,
|
||||||
ZERO_ADDRESS,
|
ZERO_ADDRESS,
|
||||||
algoPoolParams,
|
algoPoolParams,
|
||||||
|
@ -83,6 +83,7 @@ export default function Download({
|
|||||||
consumeMarketSwapFee: '0'
|
consumeMarketSwapFee: '0'
|
||||||
}
|
}
|
||||||
const _orderPriceAndFees = await getOrderPriceAndFees(
|
const _orderPriceAndFees = await getOrderPriceAndFees(
|
||||||
|
web3,
|
||||||
asset,
|
asset,
|
||||||
ZERO_ADDRESS,
|
ZERO_ADDRESS,
|
||||||
paramsForPool
|
paramsForPool
|
||||||
|
Loading…
Reference in New Issue
Block a user