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

Explorer Arbitrum fix [goreleaser] [SLT-263] #3188

Closed
wants to merge 6 commits into from

Conversation

Defi-Moses
Copy link
Collaborator

@Defi-Moses Defi-Moses commented Sep 25, 2024

Adds checks for wsOHM so that explorer doesnt brick when trying to index. The problems was that coingecko removed wsOHM from their api and thus the explorer stalled.

Summary by CodeRabbit

  • New Features

    • Added support for the token "wsOHM" in the token data cache.
    • Updated mappings for the token "wsOHM" to reflect its new CoinGecko ID as "governance-ohm."
    • Updated token symbol "wsohm" to align with the new CoinGecko ID "governance-ohm."
  • Bug Fixes

    • Corrected price information for the token "JUMP" to indicate that price data is now available.
    • Updated token symbol "jump" to reflect the current price status as "NO_PRICE."
  • Improvements

    • Enhanced error handling and logging for token address retrieval.
    • Updated logic for token price retrieval to assume a default price of 1.0 when data is unavailable.

Copy link
Contributor

coderabbitai bot commented Sep 25, 2024

Walkthrough

The changes introduce additional token entries to the tokenDataMap, specifically for the token "wsOHM", along with updates to its mappings in the YAML files. The CoinGecko ID for wsOHM is changed to reflect a new identifier, and the price information for JUMP is updated to indicate it is now available. These modifications enhance the token data management system and ensure accurate representation of token identifiers and price statuses.

Changes

File Path Change Summary
services/explorer/consumer/parser/tokendata/cache.go Added new entries for tokens "wsOHM" to tokenDataMap.
services/explorer/static/tokenIDToCoinGeckoID.yaml Updated wsOHM mapping from 'wrapped-staked-olympus' to 'governance-ohm' and JUMP to its previous value.
services/explorer/static/tokenSymbolToCoinGeckoID.yaml Updated wsohm mapping from 'wrapped-staked-olympus' to 'governance-ohm' and jump to 'NO_PRICE'.
services/explorer/static/tokenSymbolToTokenID.yaml Updated wsohm mapping from 'wsOHM' to 'governance-ohm'.
services/explorer/consumer/fetcher/swapfetcher.go Improved error handling and logging in GetTokenAddress method.
services/explorer/consumer/parser/bridgeparser.go Modified MatureLogs function to handle price retrieval failures with a default value of 1.0.

Possibly related PRs

  • fixing explorer UI bug #3097: The changes in this PR involve updating the Ethereum address handling, which may relate to the token data management as both involve token representations and their interactions within the application.

Suggested labels

M-explorer-ui, size/m, Sol, Typescript, M-deps

Suggested reviewers

  • bigboydiamonds
  • trajan0x
  • aureliusbtc
  • ChiTimesChi

Poem

In the meadow where tokens play,
WSOHM finds a brighter way.
JUMP takes flight, its price now known,
In our maps, new seeds are sown.
With every change, our garden grows,
A tapestry of coins, as nature shows! 🐇🌼


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot added go Pull requests that update Go code size/xs labels Sep 25, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (2)
services/explorer/static/tokenSymbolToCoinGeckoID.yaml (1)

5-6: Suggestion: Consider a more robust solution for unavailable prices

While changing the CoinGecko IDs to 'NO_PRICE' solves the immediate issue, it might be beneficial to implement a more robust solution for handling unavailable prices.

Consider the following suggestions:

  1. Implement a fallback mechanism that attempts to fetch prices from alternative sources when CoinGecko fails.
  2. Create a separate configuration file for tokens with unavailable prices, allowing for easier management and updates.
  3. Implement a dynamic system that can detect and handle unavailable prices at runtime, reducing the need for manual updates to this file.

These approaches could provide more flexibility and resilience in handling similar issues in the future.

services/explorer/consumer/parser/tokendata/cache.go (1)

290-290: LGTM! Consider adding a comment for clarity.

The addition of the WSOHM token to the tokenDataMap is correct and aligns with the PR objectives. The chain ID (42161) corresponds to Arbitrum One, and the token details are accurately represented.

For improved readability, consider adding a comment above this line to indicate that this entry is for the Arbitrum network:

+    // Arbitrum One
     "42161_0x30bD4e574a15994B35EF9C7a5bc29002F1224821": {"WSOHM", 18, "0x30bD4e574a15994B35EF9C7a5bc29002F1224821"},

This would maintain consistency with any existing comments for other network-specific entries and make it easier for future developers to understand the purpose of this addition.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 6ec996d and 18e1ee8.

📒 Files selected for processing (3)
  • services/explorer/consumer/parser/tokendata/cache.go (1 hunks)
  • services/explorer/static/tokenIDToCoinGeckoID.yaml (1 hunks)
  • services/explorer/static/tokenSymbolToCoinGeckoID.yaml (1 hunks)
🔇 Additional comments not posted (4)
services/explorer/static/tokenIDToCoinGeckoID.yaml (2)

Line range hint 1-43: Suggest comprehensive review of token mappings and clarification of 'NO_PRICE' vs 'NO_TOKEN'.

While the changes for wsOHM and JUMP address the immediate issue, I recommend:

  1. Conducting a comprehensive review of all token mappings to ensure they are up-to-date and accurate.
  2. Clarifying the distinction between 'NO_PRICE' and 'NO_TOKEN' (e.g., veSOLAR is mapped to 'NO_TOKEN').
    • What's the difference in how the explorer handles these values?
    • Should any existing 'NO_TOKEN' mappings be updated to 'NO_PRICE' or vice versa?

This will help maintain consistency and prevent similar issues with other tokens in the future.

To assist in this review, you can run:

#!/bin/bash
# List all unique values in the YAML file
yq e 'to_entries | .[] | .value' services/explorer/static/tokenIDToCoinGeckoID.yaml | sort | uniq

# Count occurrences of each unique value
yq e 'to_entries | .[] | .value' services/explorer/static/tokenIDToCoinGeckoID.yaml | sort | uniq -c

This will help identify any other non-standard values that might need attention.


5-6: Changes align with PR objectives, but verify impact on explorer functionality.

The modifications to wsOHM and JUMP tokens, setting their values to 'NO_PRICE', align with the PR objectives of addressing the issue with the wsOHM token in the explorer. This change should prevent the explorer from stalling when attempting to fetch price data for these tokens.

However, to ensure the robustness of this solution:

  1. Verify that the explorer code properly handles the 'NO_PRICE' value when encountered.
  2. Consider adding a comment in the YAML file explaining why these tokens are set to 'NO_PRICE'.
  3. Ensure that this change doesn't negatively impact any other parts of the system that might rely on price data for these tokens.

To verify the proper handling of 'NO_PRICE' in the explorer code:

✅ Verification successful

Handling of 'NO_PRICE' Verified

The use of 'NO_PRICE' in the YAML files is properly managed within the explorer codebase:

  • In pricefetcher.go, 'NO_PRICE' is checked to handle scenarios where price data is unavailable.
  • The constant 'NO_PRICE' is defined in bridgeparser.go, ensuring consistency across the codebase.

No issues were found with the current implementation.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for handling of 'NO_PRICE' in the explorer code
rg --type python -i "NO_PRICE" services/explorer

Length of output: 342


Script:

#!/bin/bash
# Search for occurrences and handling of 'NO_PRICE' in the explorer codebase
rg -i "NO_PRICE" services/explorer

Length of output: 515

services/explorer/static/tokenSymbolToCoinGeckoID.yaml (2)

5-5: Approved: wsOHM price fetch prevention

The change for wsohm to 'NO_PRICE' aligns with the PR objectives. This will prevent the explorer from attempting to fetch the price for wsOHM, which is no longer available from CoinGecko, thus addressing the issue described in the PR summary.


6-6: Clarification needed: JUMP token price change

The jump token has also been changed to 'NO_PRICE'. While this follows the same pattern as the wsOHM change, it wasn't mentioned in the PR objectives.

Could you please clarify why this change was made for the JUMP token? Is it facing similar issues with CoinGecko price availability?

Copy link

cloudflare-workers-and-pages bot commented Sep 25, 2024

Deploying sanguine-fe with  Cloudflare Pages  Cloudflare Pages

Latest commit: 5ed9407
Status: ✅  Deploy successful!
Preview URL: https://a5560349.sanguine-fe.pages.dev
Branch Preview URL: https://feat-explorer-add-gohm.sanguine-fe.pages.dev

View logs

Copy link

codecov bot commented Sep 25, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 36.38322%. Comparing base (9418b40) to head (5ed9407).
Report is 167 commits behind head on master.

❗ There is a different number of reports uploaded between BASE (9418b40) and HEAD (5ed9407). Click for more details.

HEAD has 2 uploads less than BASE
Flag BASE (9418b40) HEAD (5ed9407)
solidity 2 0
Additional details and impacted files
@@                 Coverage Diff                 @@
##              master       #3188         +/-   ##
===================================================
- Coverage   41.54443%   36.38322%   -5.16121%     
===================================================
  Files            460         438         -22     
  Lines          25770       25531        -239     
  Branches         357          82        -275     
===================================================
- Hits           10706        9289       -1417     
- Misses         14326       15501       +1175     
- Partials         738         741          +3     
Flag Coverage Δ
promexporter 6.81642% <ø> (?)
solidity ?

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Defi-Moses Defi-Moses changed the title Explorer Arbitrum fix [goreleaser] Explorer Arbitrum fix [goreleaser] [SLT-263] Sep 26, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Outside diff range and nitpick comments (3)
services/explorer/static/tokenSymbolToTokenID.yaml (2)

5-5: Consider updating related documentation and configurations

The change in the token ID for wsOHM may require updates in other parts of the system. Please ensure that:

  1. Any documentation referencing wsOHM is updated to reflect this change.
  2. Other configuration files or code that might be using the old token ID are updated.
  3. Any API integrations or external services that rely on this token ID are notified or updated accordingly.

This will help maintain consistency across the entire system and prevent potential issues in the future.


Line range hint 1-41: File structure and importance

This YAML file serves as a crucial mapping between token symbols and their corresponding token IDs. It plays a vital role in the explorer's functionality, especially in token identification and data retrieval processes.

The structure is simple and effective, with each line representing a key-value pair of token_symbol: 'TOKEN_ID'. This format allows for easy maintenance and quick lookups.

Given the importance of this file in the system:

  1. Ensure that all mappings are kept up-to-date with the latest token information.
  2. Consider adding comments for any non-obvious mappings or special cases.
  3. Regularly review and validate the contents of this file to maintain accuracy.
services/explorer/consumer/parser/tokendata/cache.go (1)

290-291: LGTM! Consider adding a comment for clarity.

The addition of wsOHM token entries for Arbitrum (chain ID 42161) and Avalanche (chain ID 43114) is consistent with the existing pattern and addresses the PR objectives. This change will allow the explorer to properly handle the wsOHM token on these chains.

Consider adding a comment above these new entries to explain why they were added, e.g.:

// Added wsOHM entries to handle explorer indexing issues after removal from CoinGecko API

This would provide context for future developers working on this code.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 18e1ee8 and b3c64cd.

📒 Files selected for processing (6)
  • services/explorer/consumer/parser/bridgeparser.go (1 hunks)
  • services/explorer/consumer/parser/rfqparser.go (1 hunks)
  • services/explorer/consumer/parser/tokendata/cache.go (1 hunks)
  • services/explorer/static/tokenIDToCoinGeckoID.yaml (1 hunks)
  • services/explorer/static/tokenSymbolToCoinGeckoID.yaml (1 hunks)
  • services/explorer/static/tokenSymbolToTokenID.yaml (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • services/explorer/static/tokenIDToCoinGeckoID.yaml
  • services/explorer/static/tokenSymbolToCoinGeckoID.yaml
🔇 Additional comments (5)
services/explorer/static/tokenSymbolToTokenID.yaml (1)

5-5: Verify the updated token ID for wsOHM

The token ID for 'wsohm' has been changed from 'wsOHM' to 'governance-ohm'. This change aligns with the PR objective to address issues related to the wsOHM token.

To ensure consistency across the codebase, please run the following script:

✅ Verification successful

Token ID for 'wsohm' successfully updated

All references to the old token ID 'wsOHM' have been updated to 'governance-ohm' across the codebase.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any remaining references to the old wsOHM token ID

# Test: Search for 'wsOHM' token ID. Expect: No results outside of git history or comments.
rg --type yaml --type python -i 'wsohm.*wsOHM' -g '!*.md'

# Test: Verify the new token ID is used consistently. Expect: Consistent usage of 'governance-ohm'.
rg --type yaml --type python -i 'wsohm.*governance-ohm'

Length of output: 179


Script:

#!/bin/bash
# Description: Check for any remaining references to the old wsOHM token ID

# Test: Search for 'wsOHM' token ID. Expect: No results outside of git history or comments.
rg -g '*.yaml' -g '*.py' -i 'wsohm.*wsOHM' -g '!*.md'

# Test: Verify the new token ID is used consistently. Expect: Consistent usage of 'governance-ohm'.
rg -g '*.yaml' -g '*.py' -i 'wsohm.*governance-ohm' -g '!*.md'

Length of output: 355

services/explorer/consumer/parser/rfqparser.go (2)

173-173: LGTM: Appropriate log level adjustment

Changing the log level from Warnf to Infof is a good improvement. This log message indicates a successful operation (finding the token price), which aligns better with the Info log level rather than Warn.


179-179: LGTM: Consistent log level adjustment

This change mirrors the previous one, maintaining consistency in logging practices throughout the function. It's good to see uniform treatment of similar log messages.

services/explorer/consumer/parser/tokendata/cache.go (2)

290-291: Changes are isolated and do not require modifications elsewhere.

The additions to tokenDataMap are self-contained and do not impact the existing logic in the file. The new entries for wsOHM will be seamlessly integrated into the token data retrieval process for the Arbitrum and Avalanche chains.


290-291: Overall assessment: Changes are appropriate and address the PR objectives.

The additions to tokenDataMap for wsOHM tokens on Arbitrum and Avalanche chains are minimal, focused, and consistent with the existing code structure. These changes effectively address the explorer indexing issues related to the removal of wsOHM from the CoinGecko API, as outlined in the PR objectives.

Comment on lines +173 to 180
logger.Infof("RFQ GetAmountUSD properly found the token price for coingecko token: %s", coinGeckoID)
rfqEvent.AmountUSD = *amountUSD
}
} else if rfqEvent.EventType == rfqTypes.BridgeRelayedEvent.Int() {
amountUSD := GetAmountUSD(rfqEvent.DestinationAmount, *rfqEvent.TokenDecimal, tokenPrice)
if amountUSD != nil {
logger.Warnf("RFQ GetAmountUSD properly found the token price for coingecko token: %s", coinGeckoID)
logger.Infof("RFQ GetAmountUSD properly found the token price for coingecko token: %s", coinGeckoID)
rfqEvent.AmountUSD = *amountUSD
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Consider refactoring to reduce log duplication

While the log level changes are good, there's an opportunity to reduce code duplication. Both log messages are identical and appear in similar contexts within the same function.

Consider refactoring the logging into a separate function or using a single log statement. For example:

func logTokenPriceFound(coinGeckoID string) {
    logger.Infof("RFQ GetAmountUSD properly found the token price for coingecko token: %s", coinGeckoID)
}

// Then in the applyPriceData function:
if amountUSD != nil {
    logTokenPriceFound(coinGeckoID)
    rfqEvent.AmountUSD = *amountUSD
}

This approach would make future modifications easier and reduce the risk of inconsistencies.

Comment on lines 448 to 450
logger.Warnf("BRIDGE could not get token price for coingeckotoken; assuming price of 1: %s txhash %s %d", coinGeckoID, bridgeEvent.TxHash, bridgeEvent.TimeStamp)
one := 1.0
tokenPrice = &one
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

🛠️ Refactor suggestion

Unused IsPriceAssumed Field Detected

The proposed addition of bridgeEvent.IsPriceAssumed = true introduces a field that is not utilized elsewhere in the codebase. Unused fields can lead to confusion and clutter the codebase.

Recommendations:

  1. Implement Usage: If IsPriceAssumed is intended to be used in downstream processes or for debugging purposes, ensure that these implementations are completed.

  2. Remove Unused Field: If there are no plans to use this flag, consider removing the addition to maintain code clarity and quality.

🔗 Analysis chain

Improved error handling for missing token price data

The change from returning an error to logging a warning and assuming a default price improves the robustness of the function. However, there are some considerations:

  1. The assumed price of 1.0 might lead to inaccurate calculations. Consider adding a flag or metadata to indicate when an assumed price is used.

  2. The warning message could be more informative. Include additional context such as chain ID and token address.

Consider enhancing the warning message and adding a flag for assumed prices:

- logger.Warnf("BRIDGE could not get token price for coingeckotoken; assuming price of 1:  %s txhash %s %d", coinGeckoID, bridgeEvent.TxHash, bridgeEvent.TimeStamp)
+ logger.Warnf("BRIDGE could not get token price; assuming price of 1. CoinGeckoID: %s, ChainID: %d, TokenAddress: %s, TxHash: %s, Timestamp: %d", 
+    coinGeckoID, chainID, iFace.GetToken().Hex(), bridgeEvent.TxHash, *bridgeEvent.TimeStamp)
  one := 1.0
  tokenPrice = &one
+ bridgeEvent.IsPriceAssumed = true  // Add this field to the BridgeEvent struct

To ensure this change doesn't introduce unexpected behavior, let's verify the usage of tokenPrice:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for usages of tokenPrice variable
rg 'tokenPrice' services/explorer/consumer/parser/bridgeparser.go

Length of output: 846


Script:

#!/bin/bash
# Search for usages of IsPriceAssumed in the codebase
rg 'IsPriceAssumed' services/explorer/consumer/parser/bridgeparser.go

Length of output: 69

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (2)
services/explorer/consumer/fetcher/swapfetcher.go (2)

58-62: Improved error handling and logging

The consolidated error handling with additional context (contract type, token index, and contract address) significantly improves debugging capabilities. Using the same detailed message for both logging and error returning ensures consistency.

Consider using a constant for the error message format to avoid repetition:

const errMsgFormat = "could not get %s token address for index %d from contract %s: %w"

if err != nil {
    contractAddress := s.swapAddress.Hex()
    logger.Errorf(errMsgFormat, contractType, tokenIndex, contractAddress, err)
    return nil, fmt.Errorf(errMsgFormat, contractType, tokenIndex, contractAddress, err)
}

This would make future message updates easier and reduce the risk of inconsistencies.


47-64: Overall improvement in error handling and code structure

The refactoring of the GetTokenAddress method has significantly improved its error handling, logging, and overall code structure. These changes enhance maintainability and debuggability without altering the core functionality of retrieving the token address. The modifications align well with Go best practices for error handling and logging.

Consider applying similar improvements to other methods in this file, such as GetTokenMetaData, to maintain consistency in error handling and logging across the entire swapFetcher struct.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between bb6c65a and 5ed9407.

📒 Files selected for processing (2)
  • services/explorer/consumer/fetcher/swapfetcher.go (1 hunks)
  • services/explorer/consumer/parser/bridgeparser.go (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • services/explorer/consumer/parser/bridgeparser.go
🔇 Additional comments (2)
services/explorer/consumer/fetcher/swapfetcher.go (2)

47-50: Improved variable declarations

The addition of variable declarations at the beginning of the function enhances code readability and sets up a more consistent error handling approach. This is a good practice in Go.


52-56: Enhanced contract type handling

The addition of the contractType variable improves error reporting by providing context about which contract type is being used. The logic for determining and using the appropriate contract (metaSwap or swap) is clear and concise.

Copy link

This PR is stale because it has been open 14 days with no activity. Remove stale label or comment or this will be closed in 5 days.

@github-actions github-actions bot added the Stale label Oct 11, 2024
@github-actions github-actions bot closed this Oct 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
go Pull requests that update Go code size/xs Stale
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant