synapsecns/sanguine

View on GitHub
services/rfq/relayer/quoter/quoter.go

Summary

Maintainability
D
3 days
Test Coverage

File quoter.go has 721 lines of code (exceeds 500 allowed). Consider refactoring.
Open

// Package quoter submits quotes to the RFQ API for which assets the relayer is willing to relay.
package quoter

import (
    "context"
Severity: Minor
Found in services/rfq/relayer/quoter/quoter.go - About 7 hrs to fix

    Method Manager.getOriginAmount has 92 lines of code (exceeds 50 allowed). Consider refactoring.
    Open

    func (m *Manager) getOriginAmount(parentCtx context.Context, input QuoteInput) (quoteAmount *big.Int, err error) {
        ctx, span := m.metricsHandler.Tracer().Start(parentCtx, "getOriginAmount", trace.WithAttributes(
            attribute.Int(metrics.Origin, input.OriginChainID),
            attribute.Int(metrics.Destination, input.DestChainID),
            attribute.String("dest_address", input.DestTokenAddr.String()),
    Severity: Major
    Found in services/rfq/relayer/quoter/quoter.go - About 2 hrs to fix

      Method Manager.generateQuotes has 68 lines of code (exceeds 50 allowed). Consider refactoring.
      Open

      func (m *Manager) generateQuotes(parentCtx context.Context, chainID int, address common.Address, balance *big.Int, inv map[int]map[common.Address]*big.Int) (quotes []model.PutRelayerQuoteRequest, err error) {
          ctx, span := m.metricsHandler.Tracer().Start(parentCtx, "generateQuotes", trace.WithAttributes(
              attribute.Int(metrics.Origin, chainID),
              attribute.String("address", address.String()),
              attribute.String("balance", balance.String()),
      Severity: Minor
      Found in services/rfq/relayer/quoter/quoter.go - About 1 hr to fix

        Method Manager.ShouldProcess has 59 lines of code (exceeds 50 allowed). Consider refactoring.
        Open

        func (m *Manager) ShouldProcess(parentCtx context.Context, quote reldb.QuoteRequest) (res bool, err error) {
            ctx, span := m.metricsHandler.Tracer().Start(parentCtx, "shouldProcess", trace.WithAttributes(
                attribute.String("transaction_id", hexutil.Encode(quote.TransactionID[:])),
            ))
        
        
        Severity: Minor
        Found in services/rfq/relayer/quoter/quoter.go - About 1 hr to fix

          Method Manager.prepareAndSubmitQuotes has 57 lines of code (exceeds 50 allowed). Consider refactoring.
          Open

          func (m *Manager) prepareAndSubmitQuotes(ctx context.Context, inv map[int]map[common.Address]*big.Int) (err error) {
              ctx, span := m.metricsHandler.Tracer().Start(ctx, "prepareAndSubmitQuotes")
              defer func() {
                  span.SetAttributes(attribute.Bool("relay_paused", m.relayPaused.Load()))
                  metrics.EndSpanWithErr(span, err)
          Severity: Minor
          Found in services/rfq/relayer/quoter/quoter.go - About 1 hr to fix

            Method Manager.generateActiveRFQ has 54 lines of code (exceeds 50 allowed). Consider refactoring.
            Open

            func (m *Manager) generateActiveRFQ(ctx context.Context, msg *model.ActiveRFQMessage) (resp *model.ActiveRFQMessage, err error) {
                ctx, span := m.metricsHandler.Tracer().Start(ctx, "generateActiveRFQ", trace.WithAttributes(
                    attribute.String("op", msg.Op),
                    attribute.String("content", string(msg.Content)),
                ))
            Severity: Minor
            Found in services/rfq/relayer/quoter/quoter.go - About 1 hr to fix

              Method Manager.ShouldProcess has 11 return statements (exceeds 4 allowed).
              Open

              func (m *Manager) ShouldProcess(parentCtx context.Context, quote reldb.QuoteRequest) (res bool, err error) {
                  ctx, span := m.metricsHandler.Tracer().Start(parentCtx, "shouldProcess", trace.WithAttributes(
                      attribute.String("transaction_id", hexutil.Encode(quote.TransactionID[:])),
                  ))
              
              
              Severity: Major
              Found in services/rfq/relayer/quoter/quoter.go - About 1 hr to fix

                Method Manager.generateActiveRFQ has 7 return statements (exceeds 4 allowed).
                Open

                func (m *Manager) generateActiveRFQ(ctx context.Context, msg *model.ActiveRFQMessage) (resp *model.ActiveRFQMessage, err error) {
                    ctx, span := m.metricsHandler.Tracer().Start(ctx, "generateActiveRFQ", trace.WithAttributes(
                        attribute.String("op", msg.Op),
                        attribute.String("content", string(msg.Content)),
                    ))
                Severity: Major
                Found in services/rfq/relayer/quoter/quoter.go - About 45 mins to fix

                  Function NewQuoterManager has 6 arguments (exceeds 4 allowed). Consider refactoring.
                  Open

                  func NewQuoterManager(config relconfig.Config, metricsHandler metrics.Handler, inventoryManager inventory.Manager, relayerSigner signer.Signer, feePricer pricer.FeePricer, apiClient rfqAPIClient.AuthenticatedClient) (Quoter, error) {
                  Severity: Minor
                  Found in services/rfq/relayer/quoter/quoter.go - About 45 mins to fix

                    Method Manager.prepareAndSubmitQuotes has 6 return statements (exceeds 4 allowed).
                    Open

                    func (m *Manager) prepareAndSubmitQuotes(ctx context.Context, inv map[int]map[common.Address]*big.Int) (err error) {
                        ctx, span := m.metricsHandler.Tracer().Start(ctx, "prepareAndSubmitQuotes")
                        defer func() {
                            span.SetAttributes(attribute.Bool("relay_paused", m.relayPaused.Load()))
                            metrics.EndSpanWithErr(span, err)
                    Severity: Major
                    Found in services/rfq/relayer/quoter/quoter.go - About 40 mins to fix

                      Method Manager.getOriginAmount has 6 return statements (exceeds 4 allowed).
                      Open

                      func (m *Manager) getOriginAmount(parentCtx context.Context, input QuoteInput) (quoteAmount *big.Int, err error) {
                          ctx, span := m.metricsHandler.Tracer().Start(parentCtx, "getOriginAmount", trace.WithAttributes(
                              attribute.Int(metrics.Origin, input.OriginChainID),
                              attribute.Int(metrics.Destination, input.DestChainID),
                              attribute.String("dest_address", input.DestTokenAddr.String()),
                      Severity: Major
                      Found in services/rfq/relayer/quoter/quoter.go - About 40 mins to fix

                        Function NewQuoterManager has 6 return statements (exceeds 4 allowed).
                        Open

                        func NewQuoterManager(config relconfig.Config, metricsHandler metrics.Handler, inventoryManager inventory.Manager, relayerSigner signer.Signer, feePricer pricer.FeePricer, apiClient rfqAPIClient.AuthenticatedClient) (Quoter, error) {
                            qt := make(map[string][]string)
                        
                            // fix any casing issues.
                            var err error
                        Severity: Major
                        Found in services/rfq/relayer/quoter/quoter.go - About 40 mins to fix

                          Method Manager.generateQuote has 6 return statements (exceeds 4 allowed).
                          Open

                          func (m *Manager) generateQuote(ctx context.Context, input QuoteInput) (quote *model.PutRelayerQuoteRequest, err error) {
                              // Calculate the quote amount for this route
                              originAmount, err := m.getOriginAmount(ctx, input)
                              // don't quote if gas exceeds quote
                              if errors.Is(err, errMinGasExceedsQuoteAmount) {
                          Severity: Major
                          Found in services/rfq/relayer/quoter/quoter.go - About 40 mins to fix

                            Method Manager.generateQuotes has 5 arguments (exceeds 4 allowed). Consider refactoring.
                            Open

                            func (m *Manager) generateQuotes(parentCtx context.Context, chainID int, address common.Address, balance *big.Int, inv map[int]map[common.Address]*big.Int) (quotes []model.PutRelayerQuoteRequest, err error) {
                            Severity: Minor
                            Found in services/rfq/relayer/quoter/quoter.go - About 35 mins to fix

                              Method Manager.generateQuotes has 5 return statements (exceeds 4 allowed).
                              Open

                              func (m *Manager) generateQuotes(parentCtx context.Context, chainID int, address common.Address, balance *big.Int, inv map[int]map[common.Address]*big.Int) (quotes []model.PutRelayerQuoteRequest, err error) {
                                  ctx, span := m.metricsHandler.Tracer().Start(parentCtx, "generateQuotes", trace.WithAttributes(
                                      attribute.Int(metrics.Origin, chainID),
                                      attribute.String("address", address.String()),
                                      attribute.String("balance", balance.String()),
                              Severity: Major
                              Found in services/rfq/relayer/quoter/quoter.go - About 35 mins to fix

                                Method Manager.recordQuoteAmounts has 5 return statements (exceeds 4 allowed).
                                Open

                                func (m *Manager) recordQuoteAmounts(_ context.Context, observer metric.Observer) (err error) {
                                    if m.meter == nil || m.quoteAmountGauge == nil || m.currentQuotes == nil {
                                        return nil
                                    }
                                
                                
                                Severity: Major
                                Found in services/rfq/relayer/quoter/quoter.go - About 35 mins to fix

                                  Method Manager.IsProfitable has 5 return statements (exceeds 4 allowed).
                                  Open

                                  func (m *Manager) IsProfitable(parentCtx context.Context, quote reldb.QuoteRequest) (isProfitable bool, err error) {
                                      ctx, span := m.metricsHandler.Tracer().Start(parentCtx, "IsProfitable")
                                  
                                      defer func() {
                                          span.AddEvent("result", trace.WithAttributes(attribute.Bool("result", isProfitable)))
                                  Severity: Major
                                  Found in services/rfq/relayer/quoter/quoter.go - About 35 mins to fix

                                    Method Manager.generateQuotes has a Cognitive Complexity of 21 (exceeds 20 allowed). Consider refactoring.
                                    Open

                                    func (m *Manager) generateQuotes(parentCtx context.Context, chainID int, address common.Address, balance *big.Int, inv map[int]map[common.Address]*big.Int) (quotes []model.PutRelayerQuoteRequest, err error) {
                                        ctx, span := m.metricsHandler.Tracer().Start(parentCtx, "generateQuotes", trace.WithAttributes(
                                            attribute.Int(metrics.Origin, chainID),
                                            attribute.String("address", address.String()),
                                            attribute.String("balance", balance.String()),
                                    Severity: Minor
                                    Found in services/rfq/relayer/quoter/quoter.go - About 25 mins 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

                                            g.Go(func() error {
                                                recipientBlocked, err = m.screener.ScreenAddress(gctx, quote.Transaction.DestRecipient.String())
                                                if err != nil {
                                                    span.RecordError(fmt.Errorf("error screening address: %w", err))
                                                    return fmt.Errorf("error screening address: %w", err)
                                    Severity: Minor
                                    Found in services/rfq/relayer/quoter/quoter.go and 1 other location - About 30 mins to fix
                                    services/rfq/relayer/quoter/quoter.go on lines 170..177

                                    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 102.

                                    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

                                            g.Go(func() error {
                                                senderBlocked, err = m.screener.ScreenAddress(gctx, quote.Transaction.OriginSender.String())
                                                if err != nil {
                                                    span.RecordError(fmt.Errorf("error screening address: %w", err))
                                                    return fmt.Errorf("error screening address: %w", err)
                                    Severity: Minor
                                    Found in services/rfq/relayer/quoter/quoter.go and 1 other location - About 30 mins to fix
                                    services/rfq/relayer/quoter/quoter.go on lines 178..185

                                    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 102.

                                    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

                                    There are no issues that match your filters.

                                    Category
                                    Status