Skip to content

feat: add sol/btc tokens to price api#206

Merged
limitofzero merged 4 commits intomainfrom
feat/support-non-evm-for-prices
Apr 7, 2026
Merged

feat: add sol/btc tokens to price api#206
limitofzero merged 4 commits intomainfrom
feat/support-non-evm-for-prices

Conversation

@limitofzero
Copy link
Copy Markdown
Contributor

@limitofzero limitofzero commented Mar 31, 2026

Summary by CodeRabbit

  • New Features

    • Added platform mappings for Bitcoin, Solana, and Optimism (for all TargetChainId)
  • Bug Fixes

    • Broadened address validation to accept uppercase and lowercase alphanumerics.
    • Improved USD price retrieval to choose the most appropriate data source per token/address.
    • Better native-currency handling to avoid misclassifying non-EVM tokens.
    • Returns null earlier for unsupported chains during price lookups.

@limitofzero limitofzero changed the title feat: add sol/btc tokens to price api [DRAFT] feat: add sol/btc tokens to price api Mar 31, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 31, 2026

📝 Walkthrough

Walkthrough

Address validation regex broadened; CoinGecko platform mappings expanded; address normalization switched to getAddressKey with native-currency detection; USD price lookup control flow updated to choose platform vs contract endpoints and added supported-chain validation.

Changes

Cohort / File(s) Summary
API Schema
apps/api/src/app/schemas.ts
Updated OptionalAddressSchema.oneOf[0].pattern from ^(0x)?[a-fA-F0-9\\.:]{3,80}$ to ^(0x)?[a-zA-Z0-9\\.:]{3,80}$ (allows full alphanumeric chars).
CoinGecko DataSource & Types
libs/repositories/src/datasources/coingecko.ts
Expanded SUPPORTED_COINGECKO_PLATFORMS to include additional TargetChainId entries (optimistic-ethereum, bitcoin, solana); removed explicit mapping for network 10; consolidated type imports.
Address Normalization Utilities
libs/repositories/src/utils/coingeckoUtils.ts
Replaced isAddress + lowercasing with getAddressKey; added non-EVM native-token detection (NON_EVM_NATIVE_TOKENS/NATIVE_CURRENCY logic); retyped supported-chain mapping to TargetChainId and adjusted getSupportedCoingeckoChainId return type.
USD Repository — Coingecko
libs/repositories/src/repos/UsdRepository/UsdRepositoryCoingecko.ts
Changed price lookup flow to compute addressOrPlatform and choose between contract-address vs platform-id endpoints; use getAddressKey for contract path param; updated imports and conditional logic.
USD Repository — Cow
libs/repositories/src/repos/UsdRepository/UsdRepositoryCow.ts
Added additional supported-chain validation (returns null if resolved chainId is not supported); updated SDK import to include isSupportedChain.

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant UsdRepo as UsdRepository
  participant Coingecko
  participant SDK as Cow SDK

  Client->>UsdRepo: request USD price (chain, tokenAddress?, platform)
  UsdRepo->>SDK: getAddressKey(tokenAddress) / getSupportedCoingeckoChainId(chain)
  SDK-->>UsdRepo: addressOrPlatform, chainId
  alt chainId unsupported
    UsdRepo-->>Client: null
  else chainId supported
    alt addressOrPlatform is platform
      UsdRepo->>Coingecko: getMarketDataByPlatformId(platform)
    else addressOrPlatform is address
      UsdRepo->>Coingecko: getMarketDataByTokenAddress(contract_address=addressOrPlatform)
    end
    Coingecko-->>UsdRepo: market data / price
    UsdRepo-->>Client: USD price or null
  end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Poem

🐇 I hopped through patterns, widened the net,
I found more chains to dance and set,
I tidy addresses with a single key,
Prices fetched with smarter decree,
A rabbit applauds this tidy net.

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title accurately summarizes the main objective: adding support for Solana and Bitcoin tokens to the price API across multiple files (schema validation, Coingecko mappings, and repository logic).

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/support-non-evm-for-prices

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
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.

🧹 Nitpick comments (1)
libs/repositories/src/datasources/coingecko.ts (1)

31-32: Add documentation for synthetic chain IDs.

Lines 31–32 use undocumented magic numbers (1000000000, 1000000001) as synthetic chain IDs for non-EVM blockchains. A brief comment explaining their purpose and numbering scheme would improve maintainability.

Suggested documentation
 export const COINGECKO_PLATFORMS: Record<number, string | undefined> = {
   ...SUPPORTED_COINGECKO_PLATFORMS,
+  // Synthetic chain IDs for non-EVM platforms (starting at 1 billion to avoid EVM collisions)
   [1000000000]: 'bitcoin',
   [1000000001]: 'solana',
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@libs/repositories/src/datasources/coingecko.ts` around lines 31 - 32, Add a
brief comment above the synthetic chain ID mappings explaining that the numeric
keys 1000000000 and 1000000001 are intentionally reserved synthetic IDs
representing non-EVM chains (e.g., Bitcoin and Solana), describe the numbering
scheme (large reserved range starting at 1_000_000_000 for non-EVM chains), and
note that these IDs are not on-chain but used internally by the Coingecko
mapping object (the entries with keys [1000000000] and [1000000001]); update the
comment near the mapping in coingecko.ts so future maintainers understand their
purpose and must not collide with real chain IDs.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@libs/repositories/src/datasources/coingecko.ts`:
- Around line 31-32: Add a brief comment above the synthetic chain ID mappings
explaining that the numeric keys 1000000000 and 1000000001 are intentionally
reserved synthetic IDs representing non-EVM chains (e.g., Bitcoin and Solana),
describe the numbering scheme (large reserved range starting at 1_000_000_000
for non-EVM chains), and note that these IDs are not on-chain but used
internally by the Coingecko mapping object (the entries with keys [1000000000]
and [1000000001]); update the comment near the mapping in coingecko.ts so future
maintainers understand their purpose and must not collide with real chain IDs.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 45809208-ed49-48c2-a9a4-c16168a02771

📥 Commits

Reviewing files that changed from the base of the PR and between 5b58137 and 9522668.

⛔ Files ignored due to path filters (1)
  • libs/repositories/src/gen/cow/cow-api-types.ts is excluded by !**/gen/**
📒 Files selected for processing (4)
  • apps/api/src/app/schemas.ts
  • libs/repositories/src/datasources/coingecko.ts
  • libs/repositories/src/repos/UsdRepository/UsdRepositoryCoingecko.ts
  • libs/repositories/src/utils/coingeckoUtils.ts

Copy link
Copy Markdown
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.

🧹 Nitpick comments (1)
libs/repositories/src/utils/coingeckoUtils.ts (1)

62-62: Outdated comment.

The comment says "Only SupportedChainIds are supported" but the validation now also accepts AdditionalTargetChainId values.

📝 Suggested comment update
-  // Only SupportedChainIds are supported
+  // Only SupportedChainId and AdditionalTargetChainId values are supported
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@libs/repositories/src/utils/coingeckoUtils.ts` at line 62, Update the
outdated inline comment that says "Only SupportedChainIds are supported" to
reflect that validation now accepts both SupportedChainIds and
AdditionalTargetChainId values; locate the comment near the validation logic in
coingeckoUtils.ts (references to SupportedChainIds and AdditionalTargetChainId)
and replace it with a brief accurate note such as "Supports SupportedChainIds
and AdditionalTargetChainId values" so the comment matches current behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@libs/repositories/src/utils/coingeckoUtils.ts`:
- Line 62: Update the outdated inline comment that says "Only SupportedChainIds
are supported" to reflect that validation now accepts both SupportedChainIds and
AdditionalTargetChainId values; locate the comment near the validation logic in
coingeckoUtils.ts (references to SupportedChainIds and AdditionalTargetChainId)
and replace it with a brief accurate note such as "Supports SupportedChainIds
and AdditionalTargetChainId values" so the comment matches current behavior.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 0c614a03-065b-45cc-88ee-45001c90eac5

📥 Commits

Reviewing files that changed from the base of the PR and between 542a11f and 5312c9a.

📒 Files selected for processing (1)
  • libs/repositories/src/utils/coingeckoUtils.ts

*
* @default false
*/
fullBalanceCheck: boolean;
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

it's automatically generated, looks like somebody forgot to build and commit it in previous pr

@limitofzero limitofzero changed the title [DRAFT] feat: add sol/btc tokens to price api feat: add sol/btc tokens to price api Mar 31, 2026
@limitofzero limitofzero requested a review from a team March 31, 2026 21:08
@limitofzero limitofzero self-assigned this Mar 31, 2026
* }
*/
pattern: '^(0x)?[a-fA-F0-9\\.:]{3,80}$',
pattern: '^(0x)?[a-zA-Z0-9\\.:]{3,80}$',
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

As we are already using oneOf, maybe it would be better to break this down into multiple RegExps intead of a single catch-all one, so that this validation is a bit more strict.

@limitofzero limitofzero merged commit afe86e5 into main Apr 7, 2026
8 checks passed
@limitofzero limitofzero deleted the feat/support-non-evm-for-prices branch April 7, 2026 12:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants