-
Notifications
You must be signed in to change notification settings - Fork 65
fix: add onramp and offramp liquidity fetch methods with unit tests #839
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
base: master
Are you sure you want to change the base?
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Note Other AI code review bot(s) detectedCodeRabbit 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. WalkthroughUpdated 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
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
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes
Possibly related PRs
Suggested reviewers
Poem
Pre-merge checks and finishing touches✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
Summary of ChangesHello @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
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this 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.
There was a problem hiding this 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: Useundefinedor omit optional parameter instead ofnull.The
gasRefillparameter is defined as optional (gasRefill?: bigint) in the method signature, but the test passesnull. For optional parameters in TypeScript, it's more idiomatic to either omit the parameter or passundefined.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:
OfframpLiquidityV2usestoken: Address(line 60)OnrampLiquidityusestokenAddress: 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.,
tokenAddressin both) for a more predictable API surface.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 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.tssdk/src/gateway/client.tssdk/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 withOnrampLiquidity.Similar to
fetchOfframpLiquidityV2, this method returns raw JSON (line 541) without transformation, but theOnrampLiquiditytype declares numeric fields asbigint. 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), };
There was a problem hiding this 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
📒 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
There was a problem hiding this 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
undefinedforgasRefillis correct.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 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.tssdk/src/gateway/client.tssdk/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
tokenAddressnaming 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
fetchOnrampLiquiditymethod is well-implemented:
- Correctly handles optional
gasRefillparameter- 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.
📝 PR Description
Requested UI Changes
min_amountandmax_amountusing the new SDK liquidity methods.Amount to sell at max allowed {0.5}Amount to sell at min allowed {0.001}Summary by CodeRabbit
New Features
Tests