Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "node-ts",
"version": "3.0.19",
"version": "3.0.20",
"description": "Nevermined Node",
"main": "main.ts",
"scripts": {
Expand Down Expand Up @@ -131,5 +131,6 @@
]
},
"author": "Nevermined",
"license": "Apache-2.0"
"license": "Apache-2.0",
"packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
}
24 changes: 21 additions & 3 deletions src/access/access.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import { AssetResult, NeverminedService } from '../shared/nevermined/nvm.service
import { TransferDto } from './dto/transfer'
import { UploadDto } from './dto/upload'
import { UploadResult } from './dto/upload-result'
import { formatUnits } from 'viem'

export enum UploadBackends {
IPFS = 'ipfs',
Expand Down Expand Up @@ -254,14 +255,31 @@ export class AccessController {
if (!this.backendService.isBackendEnabled()) {
Logger.log(`NVM Backend not enabled, skipping tracking transaction in the database`)
} else {
const assetPrice = this.nvmService.getAssetPrice(service) / 10n ** BigInt(4)
const assetPrice = this.nvmService.getAssetPrice(service).getTotalPrice()
const erc20TokenAddress =
this.nvmService.getAssetPrice(service)?.getTokenAddress() ||
this.nvmService.getNevermined().utils.token.getAddress()

let currency: string
let decimals: number
if (erc20TokenAddress === ZeroAddress) {
currency = 'ETH'
decimals = 18
} else {
const erc20 = await this.nvmService.getNevermined().contracts.loadErc20(erc20TokenAddress)
currency = await erc20.symbol()
decimals = await erc20.decimals()
}

const priceHighestDenomination = +formatUnits(assetPrice, decimals)

const assetTx: AssetTransaction = {
assetDid: did.getDid(),
assetOwner: subscriptionDDO.proof.creator,
assetConsumer: transferData.nftReceiver,
txType: 'Mint',
price: (Number(assetPrice) / 100).toString(),
currency: 'USDC',
price: priceHighestDenomination.toString(),
currency: currency,
paymentType: 'Crypto',
txHash: JSON.stringify(txs),
metadata: '',
Expand Down
5 changes: 3 additions & 2 deletions src/shared/nevermined/nvm.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
StreamableFile,
} from '@nestjs/common'
import {
AssetPrice,
DDO,
DDOError,
DDOServiceNotFoundError,
Expand Down Expand Up @@ -472,10 +473,10 @@ export class NeverminedService {
return Number(duration) || 0
}

public getAssetPrice(service: ServiceCommon): bigint {
public getAssetPrice(service: ServiceCommon): AssetPrice {
const assetPrice = DDO.getAssetPriceFromService(service)

if (assetPrice) return assetPrice.getTotalPrice()
if (assetPrice) return assetPrice
throw new DDOError(`No price found for asset ${service.index}`)
}

Expand Down