Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Created function for retriving datatoken decimals. #264

Merged
merged 43 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from 40 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
b148911
Created function for retriving datatoken decimals.
mariacarmina Feb 14, 2024
8969a69
Removed TODO comments.
mariacarmina Feb 14, 2024
1709245
override envs.
mariacarmina Feb 15, 2024
7c2d1cb
moved to integration to have barge
mariacarmina Feb 15, 2024
c00ce4f
fix conflicts.
mariacarmina Feb 16, 2024
4d0f067
added debug error log
mariacarmina Feb 16, 2024
c3f1df8
stringify.
mariacarmina Feb 16, 2024
a1bbeb9
removed to string.
mariacarmina Feb 16, 2024
7efb499
runs only fee tests.
mariacarmina Feb 16, 2024
f827f2d
fix
mariacarmina Feb 16, 2024
1f019b6
changed url.
mariacarmina Feb 16, 2024
c8b19a7
changed logic.
mariacarmina Feb 16, 2024
747187e
fix provider issue.
mariacarmina Feb 16, 2024
1792abc
debug.
mariacarmina Feb 19, 2024
ec75c7d
debug 2.
mariacarmina Feb 19, 2024
c548364
fix test.
mariacarmina Feb 19, 2024
357e93c
refactor checkFee.
mariacarmina Feb 19, 2024
dcf2bda
updated test.
mariacarmina Feb 19, 2024
f5f3ce0
fix api call.
mariacarmina Feb 19, 2024
c6f3925
added log.
mariacarmina Feb 19, 2024
b401bf2
added more logs
mariacarmina Feb 19, 2024
b137104
added more logs
mariacarmina Feb 19, 2024
3b0cf68
comment
mariacarmina Feb 19, 2024
3a20418
console logs
mariacarmina Feb 19, 2024
96b4b14
fix buffer reading.
mariacarmina Feb 19, 2024
78d5ddf
remove to string.
mariacarmina Feb 19, 2024
8fb278d
fix
mariacarmina Feb 19, 2024
2e5aa48
bring tests back.
mariacarmina Feb 19, 2024
3319f7e
Merge branch 'develop' into datatoken-decimals
mariacarmina Feb 19, 2024
9591a35
decreaze timeout per tx.
mariacarmina Feb 19, 2024
38f4b57
fix review.
mariacarmina Feb 26, 2024
31f3d79
fix review pt.2
mariacarmina Feb 26, 2024
010e35b
Merge branch 'develop' into datatoken-decimals
mariacarmina Feb 28, 2024
7248520
fix conflicts
mariacarmina Mar 11, 2024
8821732
fix conflict
mariacarmina Mar 11, 2024
b85df6b
Merge branch 'develop' into datatoken-decimals
mariacarmina Mar 11, 2024
500e496
fix
mariacarmina Mar 11, 2024
bda3788
Merge branch 'develop' into datatoken-decimals
mariacarmina Mar 18, 2024
072253f
remove file.
mariacarmina Mar 18, 2024
db08735
fix.
mariacarmina Mar 18, 2024
4296cc9
Merge branch 'develop' into datatoken-decimals
mariacarmina Mar 18, 2024
b159fb5
return default value.
mariacarmina Mar 18, 2024
3b3fdc2
added util function.
mariacarmina Mar 19, 2024
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
24 changes: 7 additions & 17 deletions src/components/core/utils/feesHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import type { ComputeEnvironment } from '../../../@types/C2D.js'
import {
JsonRpcApiProvider,
ethers,
Contract,
Interface,
BigNumberish,
parseUnits,
Expand All @@ -11,8 +10,11 @@ import {
import { FeeTokens, ProviderFeeData, ProviderFeeValidation } from '../../../@types/Fees'
import { DDO } from '../../../@types/DDO/DDO'
import { Service } from '../../../@types/DDO/Service'

import { verifyMessage, getJsonRpcProvider } from '../../../utils/blockchain.js'
import {
getDatatokenDecimals,
verifyMessage,
getJsonRpcProvider
} from '../../../utils/blockchain.js'
import { getConfiguration } from '../../../utils/config.js'
import { CORE_LOGGER } from '../../../utils/logging/common.js'

Expand Down Expand Up @@ -79,20 +81,7 @@ export async function createProviderFee(

if (providerFeeToken && providerFeeToken !== ZeroAddress) {
const provider = await getJsonRpcProvider(asset.chainId)

const datatokenContract = new Contract(
providerFeeToken,
ERC20Template.abi,
await provider.getSigner()
)

let decimals = 18
try {
decimals = await datatokenContract.decimals()
} catch (e) {
console.error(e)
}

const decimals = await getDatatokenDecimals(providerFeeToken, provider)
providerFeeAmountFormatted = parseUnits(providerFeeAmount.toString(10), decimals)
} else {
providerFeeAmountFormatted = BigInt(0)
Expand Down Expand Up @@ -419,6 +408,7 @@ export async function createFee(

export async function checkFee(
txId: string,
chainId: number,
providerFeesData: ProviderFeeData
// message: string | Uint8Array // the message that was signed (fee structure) ?
): Promise<boolean> {
Expand Down
10 changes: 2 additions & 8 deletions src/components/core/utils/validateOrders.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
import {
JsonRpcProvider,
JsonRpcApiProvider,
Contract,
Interface,
TransactionReceipt
} from 'ethers'
import { JsonRpcApiProvider, Contract, Interface, TransactionReceipt } from 'ethers'
import { fetchEventFromTransaction } from '../../../utils/util.js'
import ERC20Template from '@oceanprotocol/contracts/artifacts/contracts/templates/ERC20TemplateEnterprise.sol/ERC20TemplateEnterprise.json' assert { type: 'json' }
import ERC721Template from '@oceanprotocol/contracts/artifacts/contracts/templates/ERC721Template.sol/ERC721Template.json' assert { type: 'json' }
Expand Down Expand Up @@ -44,7 +38,7 @@ export async function fetchTransactionReceipt(
export async function validateOrderTransaction(
txId: string,
userAddress: string,
provider: JsonRpcProvider,
provider: JsonRpcApiProvider,
dataNftAddress: string,
datatokenAddress: string,
serviceIndex: number,
Expand Down
88 changes: 0 additions & 88 deletions src/test/unit/indexer/utils.test.ts

This file was deleted.

6 changes: 6 additions & 0 deletions src/test/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,12 @@ export function getMockSupportedNetworks(): RPCS {
network: 'development',
rpc: 'http://127.0.0.1:8545',
chunkSize: 100
},
'137': {
chainId: 137,
network: 'polygon',
rpc: 'https://polygon-rpc.com',
chunkSize: 1000
}
}
return mockSupportedNetworks
Expand Down
23 changes: 21 additions & 2 deletions src/utils/blockchain.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { ethers, Signer, JsonRpcApiProvider, JsonRpcProvider } from 'ethers'
import ERC20Template from '@oceanprotocol/contracts/artifacts/contracts/templates/ERC20TemplateEnterprise.sol/ERC20TemplateEnterprise.json' assert { type: 'json' }
import { ethers, Signer, Contract, JsonRpcApiProvider, JsonRpcProvider } from 'ethers'
import { getConfiguration } from './config.js'
import { CORE_LOGGER } from './logging/common.js'
mariacarmina marked this conversation as resolved.
Show resolved Hide resolved

export class Blockchain {
private signer: Signer
Expand All @@ -26,6 +28,18 @@ export class Blockchain {
}
}

export async function getDatatokenDecimals(
datatokenAddress: string,
mariacarmina marked this conversation as resolved.
Show resolved Hide resolved
provider: JsonRpcProvider
): Promise<number> {
const datatokenContract = new Contract(datatokenAddress, ERC20Template.abi, provider)
try {
return await datatokenContract.decimals()
} catch (err) {
CORE_LOGGER.error(`${err}`)
}
paulo-ocean marked this conversation as resolved.
Show resolved Hide resolved
}

/**
* Verify a signed message, see if signature matches address
* @param message to verify
Expand All @@ -50,6 +64,11 @@ export async function verifyMessage(
}

export async function getJsonRpcProvider(chainId: number): Promise<JsonRpcProvider> {
const networkUrl = (await getConfiguration()).supportedNetworks[chainId.toString()].rpc
const config = await getConfiguration()
if (!(`${chainId.toString()}` in config.supportedNetworks)) {
CORE_LOGGER.error(`Chain ID ${chainId.toString()} is not supported`)
mariacarmina marked this conversation as resolved.
Show resolved Hide resolved
return null
}
const networkUrl = config.supportedNetworks[chainId.toString()].rpc
return new JsonRpcProvider(networkUrl)
}
Loading