oceanprotocol/ocean.js

View on GitHub

Showing 193 of 201 total issues

Similar blocks of code found in 2 locations. Consider refactoring.
Open

  public async getBasetokenSupply(exchangeId: string): Promise<string> {
    const btSupply = await this.contract.getBTSupply(exchangeId)
    const exchange = await this.getExchange(exchangeId)
    return await this.unitsToAmount(exchange.baseToken, btSupply, +exchange.btDecimals)
  }
Severity: Major
Found in src/contracts/FixedRateExchange.ts and 1 other location - About 2 hrs to fix
src/contracts/FixedRateExchange.ts on lines 266..270

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 90.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 2 locations. Consider refactoring.
Open

      maxPriorityFeePerGas:
        (chainId === MUMBAI_NETWORK_ID || chainId === POLYGON_NETWORK_ID) &&
        Number(aggressiveFeePriorityFeePerGas) < MIN_GAS_FEE_POLYGON
          ? MIN_GAS_FEE_POLYGON
          : chainId === SEPOLIA_NETWORK_ID &&
Severity: Major
Found in src/utils/ContractUtils.ts and 1 other location - About 2 hrs to fix
src/utils/ContractUtils.ts on lines 148..158

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 87.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 2 locations. Consider refactoring.
Open

      maxFeePerGas:
        (chainId === MUMBAI_NETWORK_ID || chainId === POLYGON_NETWORK_ID) &&
        Number(aggressiveFeePerGas) < MIN_GAS_FEE_POLYGON
          ? MIN_GAS_FEE_POLYGON
          : chainId === SEPOLIA_NETWORK_ID &&
Severity: Major
Found in src/utils/ContractUtils.ts and 1 other location - About 2 hrs to fix
src/utils/ContractUtils.ts on lines 136..146

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 87.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Function createAsset has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
Open

export async function createAsset(
  name: string,
  symbol: string,
  owner: Signer,
  assetUrl: any, // files object
Severity: Minor
Found in src/utils/Assets.ts - About 2 hrs to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

NftFactory has 23 functions (exceeds 20 allowed). Consider refactoring.
Open

export class NftFactory extends SmartContractWithAddress {
  getDefaultAbi() {
    return ERC721Factory.abi as AbiItem[]
  }

Severity: Minor
Found in src/contracts/NFTFactory.ts - About 2 hrs to fix

    Function createDatatoken has 59 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      public async createDatatoken<G extends boolean = false>(
        nftAddress: string,
        address: string,
        minter: string,
        paymentCollector: string,
    Severity: Major
    Found in src/contracts/NFT.ts - About 2 hrs to fix

      Provider has 22 functions (exceeds 20 allowed). Consider refactoring.
      Open

      export class Provider {
        /**
         * Returns the provider endpoints
         * @param {string} providerUri - the provider url
         * @return {Promise<any>}
      Severity: Minor
      Found in src/services/Provider.ts - About 2 hrs to fix

        Function computeStart has 58 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          public async computeStart(
            providerUri: string,
            consumer: Signer,
            computeEnv: string,
            dataset: ComputeAsset,
        Severity: Major
        Found in src/services/Provider.ts - About 2 hrs to fix

          File Assets.ts has 263 lines of code (exceeds 250 allowed). Consider refactoring.
          Open

          import { SHA256 } from 'crypto-js'
          import { ethers, Signer } from 'ethers'
          import { ConfigHelper } from '../../src/config'
          import { hexlify } from 'ethers/lib/utils'
          import { createHash } from 'crypto'
          Severity: Minor
          Found in src/utils/Assets.ts - About 2 hrs to fix

            Similar blocks of code found in 2 locations. Consider refactoring.
            Open

              constructor(
                address: string,
                signer: Signer,
                network?: string | number,
                config?: Config,
            Severity: Major
            Found in src/contracts/AccessListFactory.ts and 1 other location - About 2 hrs to fix
            src/contracts/AccessList.ts on lines 24..33

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 81.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Similar blocks of code found in 2 locations. Consider refactoring.
            Open

              constructor(
                address: string,
                signer: Signer,
                network?: string | number,
                config?: Config,
            Severity: Major
            Found in src/contracts/AccessList.ts and 1 other location - About 2 hrs to fix
            src/contracts/AccessListFactory.ts on lines 24..33

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 81.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Function computeDelete has 55 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              public async computeDelete(
                did: string,
                consumer: Signer,
                jobId: string,
                providerUri: string,
            Severity: Major
            Found in src/services/Provider.ts - About 2 hrs to fix

              Function computeStop has 54 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                public async computeStop(
                  did: string,
                  consumerAddress: string,
                  jobId: string,
                  providerUri: string,
              Severity: Major
              Found in src/services/Provider.ts - About 2 hrs to fix

                Function createNFT has 53 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                  public async createNFT<G extends boolean = false>(
                    nftData: NftCreateData,
                    estimateGas?: G
                  ): Promise<G extends false ? string : BigNumber> {
                    if (!nftData.templateIndex) nftData.templateIndex = 1
                Severity: Major
                Found in src/contracts/NFTFactory.ts - About 2 hrs to fix

                  Function sendTx has 52 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                  export async function sendTx(
                    estGas: BigNumber,
                    signer: Signer,
                    gasFeeMultiplier: number,
                    functionToSend: ContractFunction,
                  Severity: Major
                  Found in src/utils/ContractUtils.ts - About 2 hrs to fix

                    Function computeStatus has 45 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                      public async computeStatus(
                        providerUri: string,
                        consumerAddress: string,
                        jobId?: string,
                        agreementId?: string,
                    Severity: Minor
                    Found in src/services/Provider.ts - About 1 hr to fix

                      Function createFixedRate has 44 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                        public async createFixedRate<G extends boolean = false>(
                          dtAddress: string,
                          address: string,
                          fixedRateParams: FreCreationParams,
                          estimateGas?: G
                      Severity: Minor
                      Found in src/contracts/Datatoken.ts - About 1 hr to fix

                        Function createDatatoken has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
                        Open

                          public async createDatatoken<G extends boolean = false>(
                            nftAddress: string,
                            address: string,
                            minter: string,
                            paymentCollector: string,
                        Severity: Minor
                        Found in src/contracts/NFT.ts - About 1 hr to fix

                        Cognitive Complexity

                        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                        A method's cognitive complexity is based on a few simple rules:

                        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                        • Code is considered more complex for each "break in the linear flow of the code"
                        • Code is considered more complex when "flow breaking structures are nested"

                        Further reading

                        Similar blocks of code found in 2 locations. Consider refactoring.
                        Open

                          public async getDenylistContract(dtAddress: string): Promise<string> {
                            const dtContract = this.getContract(dtAddress, this.getDefaultAbi())
                            const denyList = await dtContract.getDenyListContract()
                            return denyList
                          }
                        Severity: Major
                        Found in src/contracts/Datatoken4.ts and 1 other location - About 1 hr to fix
                        src/contracts/Datatoken4.ts on lines 45..49

                        Duplicated Code

                        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                        Tuning

                        This issue has a mass of 69.

                        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                        Refactorings

                        Further Reading

                        Similar blocks of code found in 2 locations. Consider refactoring.
                        Open

                          public async getNftPermissions(nftAddress: string, address: string): Promise<NftRoles> {
                            const nftContract = this.getContract(nftAddress)
                            const roles = await nftContract.getPermissions(address)
                            return roles
                          }
                        Severity: Major
                        Found in src/contracts/NFT.ts and 1 other location - About 1 hr to fix
                        src/contracts/Datatoken.ts on lines 695..702

                        Duplicated Code

                        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                        Tuning

                        This issue has a mass of 69.

                        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                        Refactorings

                        Further Reading

                        Severity
                        Category
                        Status
                        Source
                        Language