Skip to content

Conversation

@nakul1010
Copy link
Contributor

@nakul1010 nakul1010 commented Nov 5, 2025

📝 PR Description

  • Add onramp and offramp liquidity methods that give min and max amount

Requested UI Changes

  • Use the new liquidity methods
  • Currently, entering a large amount triggers an “Insufficient Liquidity” or rate limit error, while very small amounts may result in a “Fee Insufficient” error.
Screenshot 2025-11-05 at 5 26 02 PM
  • Instead, I’d prefer that users never see these errors. The UI should restrict input to values between min_amount and max_amount using the new SDK liquidity methods.
Screenshot 2025-11-05 at 5 26 13 PM
  • If the entered amount falls outside the given liquidity range, the corresponding cell should highlight in red.
    • Eg: user entered amount 1 BTC, but max allowed is 0.5. err msg in UI: Amount to sell at max allowed {0.5}
    • Eg: user entered amount 0.00001 BTC, but min allowed is 0.001. err msg in UI: Amount to sell at min allowed {0.001}
  • Pass zero address to method if user has not connected the wallet.

Summary by CodeRabbit

  • New Features

    • Added two liquidity queries to the Gateway client: an updated offramp (V2) and an onramp liquidity endpoint.
    • Onramp query supports an optional gas refill parameter.
    • Liquidity responses now include sats-based fields and minimum-quote details for clearer limits and totals.
  • Tests

    • Added unit tests covering the new offramp V2 and onramp liquidity responses.

@vercel
Copy link

vercel bot commented Nov 5, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
bob-docs Ready Ready Preview Comment Nov 5, 2025 11:55am

@nakul1010 nakul1010 requested a review from gregdhill November 5, 2025 08:59
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 5, 2025

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Walkthrough

Updated Gateway API client to fetch v2 offramp liquidity and to fetch onramp liquidity; adjusted types for sats-based fields and minimum offramp quote; added tests that mock the new endpoints (with duplicated test blocks present); bumped SDK package version.

Changes

Cohort / File(s) Change Summary
API Client
sdk/src/gateway/client.ts
Replaced/added methods to call v2 offramp liquidity and new onramp liquidity endpoints: fetchOfframpLiquidity(token, userAddress) now targets /v2/offramp-liquidity and fetchOnrampLiquidity(token, userAddress, gasRefill?) calls /onramp-liquidity. Query params assembled, non-OK responses handled, JSON mapped to typed responses with numeric string → BigInt conversions.
Types
sdk/src/gateway/types/offramp.ts
Updated OfframpLiquidity shape (renamed fields to *InSats, tokenAddress), added MinimumOfframpQuote, and added OnrampLiquidity interface (sats-based numeric fields).
Tests
sdk/test/gateway.test.ts
Removed previous offramp test; added tests that mock /v2/offramp-liquidity and /onramp-liquidity and assert mapped results (BigInt normalized for comparison). Note: duplicated identical test blocks appear in the file; several e2e tests were skipped.
Manifest
sdk/package.json
Version bumped from 4.3.12 → 4.4.0 (metadata change).

Sequence Diagram(s)

sequenceDiagram
    participant Consumer as Client / Test
    participant Gateway as GatewayApiClient
    participant API as Gateway API

    rect rgb(220,240,255)
    Note over Consumer,Gateway: Offramp (v2) flow
    Consumer->>Gateway: fetchOfframpLiquidity(token, userAddress)
    Gateway->>API: GET /v2/offramp-liquidity?tokenAddress=...&userAddress=...
    API-->>Gateway: 200 { off-ramp JSON }
    Gateway-->>Consumer: OfframpLiquidity (mapped, BigInt fields)
    end

    rect rgb(240,230,230)
    Note over Consumer,Gateway: Onramp flow
    Consumer->>Gateway: fetchOnrampLiquidity(token, userAddress, gasRefill?)
    Gateway->>API: GET /onramp-liquidity?tokenAddress=...&userAddress=...&gasRefill=...
    API-->>Gateway: 200 { on-ramp JSON }
    Gateway-->>Consumer: OnrampLiquidity (mapped, BigInt fields)
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • Areas to focus on:
    • Query parameter names/encoding (token vs tokenAddress) and correct v2 endpoint usage in sdk/src/gateway/client.ts.
    • Correct parsing of numeric strings into BigInt and consistent field renames (e.g., maxOrderAmountInSats, total...InSats).
    • Test file duplicates in sdk/test/gateway.test.ts and skipped e2e tests.
    • Public export surface update to include OnrampLiquidity from types.

Possibly related PRs

Suggested reviewers

  • danielsimao
  • gregdhill
  • slavastartsev

Poem

🐰 I hop with sats and query strings,
Offramp v2 and onramp springs,
Types snugged tight in sat-based rows,
Tests mock the calls where data flows,
A rabbit cheers: the client grows.

Pre-merge checks and finishing touches

✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main changes: adding onramp and offramp liquidity fetch methods with unit tests. This aligns with the core modifications across client.ts, types, and tests.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/add-liquidity-apis

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.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @nakul1010, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the SDK's capabilities by integrating new methods for fetching onramp and offramp liquidity. These additions provide users with crucial information regarding available funds for transactions, supported by new data structures and robust unit tests to ensure reliability.

Highlights

  • New Liquidity Fetching Methods: Introduced fetchOfframpLiquidityV2 and fetchOnrampLiquidity to the GatewayApiClient for retrieving detailed liquidity information for both onramp and offramp operations.
  • New Data Structures for Liquidity: Added new TypeScript interfaces: OfframpLiquidityV2, MinimumOfframpQuote, and OnrampLiquidity to precisely define the structure of the fetched liquidity data.
  • Comprehensive Unit Tests: Included dedicated unit tests for both new liquidity fetching methods, ensuring their correct functionality and integration with mocked API responses. Additionally, two end-to-end tests were added but are currently skipped.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces new methods for fetching onramp and offramp liquidity, complete with type definitions and unit tests. The implementation is solid and the tests provide good coverage for the new functionality. I've identified a few areas for improvement related to code correctness, consistency, and maintainability. My feedback includes suggestions to fix a type mismatch in an interface, correct the usage of null in tests where undefined is expected, and refactor some duplicated code to enhance maintainability.

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

🧹 Nitpick comments (2)
sdk/test/gateway.test.ts (1)

1469-1469: Use undefined or omit optional parameter instead of null.

The gasRefill parameter is defined as optional (gasRefill?: bigint) in the method signature, but the test passes null. For optional parameters in TypeScript, it's more idiomatic to either omit the parameter or pass undefined.

Apply this diff:

-        const onrampLiquidity = await gatewaySDK.fetchOnrampLiquidity(tokenAddress, userAddress, null);
+        const onrampLiquidity = await gatewaySDK.fetchOnrampLiquidity(tokenAddress, userAddress);
sdk/src/gateway/types/offramp.ts (1)

57-85: Consider unifying token field naming across liquidity types.

There's an inconsistency in field naming:

  • OfframpLiquidityV2 uses token: Address (line 60)
  • OnrampLiquidity uses tokenAddress: Address (line 78)

Both represent the same concept. If these mirror different backend API responses, this is acceptable. However, if the SDK has flexibility to normalize the naming, consider using consistent field names (e.g., tokenAddress in both) for a more predictable API surface.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4076234 and 65a6957.

📒 Files selected for processing (3)
  • sdk/src/gateway/client.ts (2 hunks)
  • sdk/src/gateway/types/offramp.ts (1 hunks)
  • sdk/test/gateway.test.ts (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-06-17T11:18:53.195Z
Learnt from: slavastartsev
Repo: bob-collective/bob PR: 634
File: sdk/src/gateway/client.ts:136-140
Timestamp: 2025-06-17T11:18:53.195Z
Learning: The codebase has a requirement not to introduce discriminated unions in the Gateway SDK client methods, including the getQuote method return types in sdk/src/gateway/client.ts.

Applied to files:

  • sdk/test/gateway.test.ts
  • sdk/src/gateway/client.ts
  • sdk/src/gateway/types/offramp.ts
🧬 Code graph analysis (2)
sdk/test/gateway.test.ts (1)
sdk/src/gateway/client.ts (1)
  • MAINNET_GATEWAY_BASE_URL (80-80)
sdk/src/gateway/client.ts (2)
sdk/src/gateway/types/offramp.ts (2)
  • OfframpLiquidityV2 (58-67)
  • OnrampLiquidity (76-85)
sdk/src/gateway/tokens.ts (1)
  • getTokenAddress (460-468)
🪛 Gitleaks (8.28.0)
sdk/test/gateway.test.ts

[high] 1423-1423: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.

(generic-api-key)


[high] 1451-1451: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.

(generic-api-key)


[high] 1478-1478: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.

(generic-api-key)


[high] 1504-1504: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.

(generic-api-key)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: test
🔇 Additional comments (1)
sdk/src/gateway/client.ts (1)

511-542: Verify response type compatibility with OnrampLiquidity.

Similar to fetchOfframpLiquidityV2, this method returns raw JSON (line 541) without transformation, but the OnrampLiquidity type declares numeric fields as bigint. If the backend returns JSON numbers, type mismatches will occur.

Consider adding explicit BigInt conversion:

const rawLiquidity = await response.json();

return {
    tokenAddress: rawLiquidity.tokenAddress as Address,
    maxOrderAmountInSats: BigInt(rawLiquidity.maxOrderAmountInSats),
    totalOnrampLiquidityInSats: BigInt(rawLiquidity.totalOnrampLiquidityInSats),
    minSatsAmount: BigInt(rawLiquidity.minSatsAmount),
};

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: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1eee7c1 and 088a0fe.

📒 Files selected for processing (3)
  • sdk/src/gateway/client.ts (2 hunks)
  • sdk/src/gateway/types/offramp.ts (1 hunks)
  • sdk/test/gateway.test.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • sdk/test/gateway.test.ts
  • sdk/src/gateway/types/offramp.ts
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-06-17T11:18:53.195Z
Learnt from: slavastartsev
Repo: bob-collective/bob PR: 634
File: sdk/src/gateway/client.ts:136-140
Timestamp: 2025-06-17T11:18:53.195Z
Learning: The codebase has a requirement not to introduce discriminated unions in the Gateway SDK client methods, including the getQuote method return types in sdk/src/gateway/client.ts.

Applied to files:

  • sdk/src/gateway/client.ts
🧬 Code graph analysis (1)
sdk/src/gateway/client.ts (2)
sdk/src/gateway/types/offramp.ts (2)
  • OfframpLiquidityV2 (58-67)
  • OnrampLiquidity (78-87)
sdk/src/gateway/tokens.ts (1)
  • getTokenAddress (460-468)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: test

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

🧹 Nitpick comments (2)
sdk/test/gateway.test.ts (2)

1395-1426: Consider asserting BigInt fields directly.

The test normalizes BigInt values to numbers for comparison, which works but loses type safety. Consider asserting the BigInt fields directly:

-        const normalized = JSON.parse(
-            JSON.stringify(offrampLiquidity, (_, v) => (typeof v === 'bigint' ? Number(v) : v))
-        );
-
-        // Match only the liquidity details, skip tokenAddress
-        expect(normalized).toMatchObject(mock_offramp_liquidity);
+        expect(offrampLiquidity.tokenAddress).toBe(tokenAddress);
+        expect(offrampLiquidity.maxOrderAmountInSats).toBe(BigInt(50000000));
+        expect(offrampLiquidity.totalOfframpLiquidityInSats).toBe(BigInt(53304097));
+        expect(offrampLiquidity.minimumOfframpQuote.minimumAmountInSats).toBe(BigInt(666));
+        expect(offrampLiquidity.minimumOfframpQuote.calculatedForFeeRate).toBe(BigInt(1));

This preserves type information and makes the test more explicit about what's being validated.


1428-1454: Consider direct BigInt assertions here as well.

Similar to the offramp test, consider asserting BigInt fields directly instead of normalizing. The undefined for gasRefill is correct.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 088a0fe and a660fb6.

📒 Files selected for processing (4)
  • sdk/package.json (1 hunks)
  • sdk/src/gateway/client.ts (2 hunks)
  • sdk/src/gateway/types/offramp.ts (1 hunks)
  • sdk/test/gateway.test.ts (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • sdk/package.json
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: slavastartsev
Repo: bob-collective/bob PR: 634
File: sdk/src/gateway/client.ts:136-140
Timestamp: 2025-06-17T11:18:53.195Z
Learning: The codebase has a requirement not to introduce discriminated unions in the Gateway SDK client methods, including the getQuote method return types in sdk/src/gateway/client.ts.
📚 Learning: 2025-06-17T11:18:53.195Z
Learnt from: slavastartsev
Repo: bob-collective/bob PR: 634
File: sdk/src/gateway/client.ts:136-140
Timestamp: 2025-06-17T11:18:53.195Z
Learning: The codebase has a requirement not to introduce discriminated unions in the Gateway SDK client methods, including the getQuote method return types in sdk/src/gateway/client.ts.

Applied to files:

  • sdk/test/gateway.test.ts
  • sdk/src/gateway/client.ts
  • sdk/src/gateway/types/offramp.ts
🧬 Code graph analysis (2)
sdk/test/gateway.test.ts (2)
sdk/src/gateway/tokens.ts (1)
  • SYMBOL_LOOKUP (395-395)
sdk/src/gateway/client.ts (1)
  • MAINNET_GATEWAY_BASE_URL (79-79)
sdk/src/gateway/client.ts (2)
sdk/src/gateway/types/offramp.ts (2)
  • OfframpLiquidity (48-57)
  • OnrampLiquidity (68-77)
sdk/src/gateway/tokens.ts (1)
  • getTokenAddress (460-468)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: test
🔇 Additional comments (4)
sdk/src/gateway/types/offramp.ts (1)

47-77: LGTM! Type definitions are well-structured.

The updated type definitions are consistent and well-documented:

  • Field renaming to include "InSats" suffix improves clarity
  • tokenAddress naming is consistent across interfaces
  • All numeric fields appropriately typed as bigint
  • JSDoc comments provide clear context
sdk/src/gateway/client.ts (2)

451-487: Error handling is correct but duplicated.

The method correctly transforms the response to BigInt values and uses the v2 endpoint. However, the error handling pattern is duplicated across multiple methods in this class.

A past review comment suggested extracting this into a helper method, which would improve maintainability. This is a minor refactor that can be addressed in a future PR if desired.


489-527: Method implementation looks good.

The fetchOnrampLiquidity method is well-implemented:

  • Correctly handles optional gasRefill parameter
  • Transforms response fields to BigInt
  • Uses appropriate endpoint

The error handling pattern is duplicated from fetchOfframpLiquidity, but as mentioned in a past review comment, this is a minor refactor that can be addressed separately.

sdk/test/gateway.test.ts (1)

1395-1513: No duplicates found—code is correct.

Verification confirms each test appears only once. The AI summary's mention of duplicate tests was inaccurate. The four tests (offramp unit, onramp unit, and two skipped e2e tests) are unique within the file.

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