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