Skip to content

Conversation

@slavastartsev
Copy link
Contributor

@slavastartsev slavastartsev commented May 20, 2025

Summary by CodeRabbit

  • New Features

    • Introduced a unified order execution method supporting onramp, offramp, and staking flows with wallet integration.
    • Added a utility for consistent token address resolution based on chain and token symbol.
    • Added a method to aggregate and retrieve both onramp and offramp orders for users.
  • Bug Fixes

    • Corrected Bitcoin address handling and validation.
    • Enhanced error messages and type safety in order and transaction processes.
    • Ensured consistent initialization of data buffers to avoid undefined values.
  • Refactor

    • Centralized token address resolution and simplified contract interaction logic.
    • Enforced non-null assertions in strategy asset state handling.
    • Improved handling of optional properties in transaction inputs and outputs.
    • Adjusted timestamp types from bigint to number for order data.
    • Improved handling of optional tapLeafScript in transaction size estimation.
  • Tests

    • Expanded test coverage with new cases for order execution and parameter updates.
    • Updated test assertions and parameter naming for accuracy.
  • Chores

    • Enabled strict null checks in TypeScript configuration for improved code robustness.

@vercel
Copy link

vercel bot commented May 20, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
bob-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 23, 2025 1:41pm

@coderabbitai
Copy link
Contributor

coderabbitai bot commented May 20, 2025

"""

Walkthrough

This update refactors the GatewayApiClient to unify quote execution for onramp, offramp, and staking orders via a new executeQuote method. It introduces a getTokenAddress utility for token resolution, tightens type safety, improves error handling, and updates related types and tests. Additional refinements include strict null checks, buffer initialization, and minor code style improvements.

Changes

File(s) Change Summary
sdk/src/gateway/client.ts Refactored GatewayApiClient with discriminated union in getQuote, replaced manual token address resolution with getTokenAddress, enhanced error messages, changed orderTimestamp from bigint to number, added unified executeQuote method for onramp/offramp/stake flows integrating wallet signing and contract calls, renamed and added order retrieval methods, improved type annotations, imports, and removed unnecessary awaits.
sdk/src/gateway/tokens.ts Added getTokenAddress function to resolve token addresses or symbols by chain, validating input and throwing on unknown tokens.
sdk/src/gateway/types.ts Renamed BuildStakeParams to StakeParams; refined strategyFunctionName type; renamed account to address; removed bitcoinUserAddress from GatewayQuoteParams; renamed GatewayOrderResponse and GatewayOrder to OnrampOrderResponse and OnrampOrder; changed outputScript to hex-prefixed string literal type; changed orderTimestamp from bigint to number in offramp types; allowed nullable transaction hashes in OfframpOrder.
sdk/src/gateway/strategy.ts Added zeroAddress import; removed TypeScript expect-error; added fallback empty string for defillamaPoolId; enforced non-null assertions on multicall results; set allowFailure: false in multicall calls.
sdk/src/inscription.ts Ensured Inscription.body is always a Buffer, defaulting to empty buffer when undefined.
sdk/src/ordinal-api/index.ts Moved confirmations property earlier in OutputJson interface without changing type or semantics.
sdk/src/ordinals/commit.ts Replaced array access with .at(-1) for last witness element; assigned controlBlock fallback to empty buffer.
sdk/src/ordinals/index.ts Conditionally wrapped tapLeafScript in array only if defined to avoid passing undefined arrays.
sdk/src/wallet/utxo.ts Made publicKey optional in collectPossibleInputs; added error check for missing publicKey on p2tr address type; changed estimateTxFee return type to allow undefined.
sdk/test/gateway.test.ts Updated imports and types; replaced BuildStakeParams with StakeParams; corrected parameter names and address usage; adjusted mocks and assertions for type changes; added tests for executeQuote covering onramp, offramp, and stake; added combined orders retrieval test.
sdk/test/ordinal-api.test.ts Changed test assertion to partial matching and omitted confirmations property in expected output.
sdk/tsconfig.json Enabled "strictNullChecks": true for stricter null safety in TypeScript.
sdk/src/gateway/index.ts Updated export to replace GatewayOrder with OnrampOrder.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant GatewayApiClient
    participant WalletClient
    participant PublicClient
    participant BTCSigner

    User->>GatewayApiClient: executeQuote(order, btcSigner, walletClient, publicClient)
    alt Onramp
        GatewayApiClient->>GatewayApiClient: startOrder()
        GatewayApiClient->>BTCSigner: signAllInputs(psbtBase64)
        BTCSigner-->>GatewayApiClient: signedTx
        GatewayApiClient->>GatewayApiClient: finalizeOrder(signedTx)
        GatewayApiClient-->>User: bitcoinTxid
    else Offramp
        GatewayApiClient->>GatewayApiClient: createOfframpOrder()
        GatewayApiClient->>GatewayApiClient: fetchOfframpRegistryAddress()
        GatewayApiClient->>WalletClient: approve(erc20, MaxUint256) (if needed)
        GatewayApiClient->>PublicClient: simulateContractCall()
        GatewayApiClient->>WalletClient: writeContract()
        GatewayApiClient->>PublicClient: waitForTransactionReceipt()
        GatewayApiClient-->>User: txHash
    else Stake
        GatewayApiClient->>GatewayApiClient: buildStakeParams()
        GatewayApiClient->>PublicClient: simulateContractCall(with state override)
        GatewayApiClient->>WalletClient: writeContract()
        GatewayApiClient->>PublicClient: waitForTransactionReceipt()
        GatewayApiClient-->>User: txHash
    end
Loading

Possibly related PRs

  • feat: add offramp sdk methods #559: Extends and refactors GatewayApiClient with detailed offramp SDK methods and on-chain order management; this PR builds upon and refines those offramp methods and adds the unified executeQuote feature.
  • feat: sdk offramp method #506: Adds getOffRampQuoteAndRequest and related offramp order retrieval methods; overlaps with this PR’s integrated order execution and type refinements focused on offramp functionality.
  • chore: improve offramp types #598: Focuses on offramp order handling and parameter structures in GatewayApiClient, overlapping with this PR’s offramp order refactoring and method signature changes.

Suggested reviewers

  • gregdhill
  • nakul1010
  • danielsimao

Poem

A bunny hopped through code so neat,
With stricter types and nulls in retreat.
Tokens resolved, addresses found,
Onramp, offramp, stakes abound!
Buffers set and tests anew,
This patch brings order, clear and true.
🐇✨
"""


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d661536 and 3bcab53.

📒 Files selected for processing (2)
  • sdk/src/gateway/client.ts (29 hunks)
  • sdk/src/gateway/types.ts (11 hunks)
🔇 Additional comments (8)
sdk/src/gateway/types.ts (4)

10-10: Good addition of utility type for better type flexibility.

The Optional<T, K> utility type is a clean way to make specific keys optional while preserving the rest of the type structure. This improves type flexibility for API methods.


54-54: Improved type safety with union of valid function names.

The change from string to (typeof strategyCaller)[number]['name'] provides compile-time validation that only valid function names from the ABI can be used.


444-444: Consistent timestamp type conversion from bigint to number.

The conversion of orderTimestamp from bigint to number in both OfframpOrder and OnchainOfframpOrderDetails improves consistency and ease of use with JavaScript Date APIs.

Also applies to: 476-476


524-535: Well-structured discriminated union types for quote parameters.

The OnrampQuoteParams and OfframpQuoteParams types with discriminated union using the type field provide clear separation of concerns and type safety for different quote operations.

sdk/src/gateway/client.ts (4)

131-143: Excellent implementation of discriminated union overloads.

The getQuote method now provides type-safe overloads that return different types based on the input parameter type, improving the developer experience and type safety.


574-601: Improved PSBT creation with early return.

The refactored PSBT creation logic is cleaner with an early return when the PSBT is successfully created, improving code readability.


1089-1100: Well-designed unified orders method.

The new getOrders method effectively combines onramp and offramp orders with clear type discrimination, providing a unified interface for retrieving all user orders.


1170-1173: Good addition of explicit parameter typing.

Adding the explicit parameter type annotation to the viemClient function improves type clarity and developer experience.

✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this 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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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.

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

🧹 Nitpick comments (4)
sdk/src/gateway/strategy.ts (2)

264-264: Non-null assertion added for totalSupply

The non-null assertion (!) assumes that totalSupply will never be null or undefined. While this satisfies TypeScript's strict null checks, it would be safer to add runtime validation.

Consider adding validation instead of using non-null assertion:

-totalUnderlying: totalSupply!,
+totalUnderlying: totalSupply ?? 0n,

322-323: Non-null assertions in return values

Similar to previous comments, the use of non-null assertions here assumes these values will always be present.

Add validation:

-address: underlyingAddress!,
-totalUnderlying: totalSupply!,
+address: underlyingAddress ?? zeroAddress,
+totalUnderlying: totalSupply ?? 0n,
sdk/src/gateway/types.ts (1)

396-400: Consider validating hex length for outputScript

Confining outputScript to 0x${string} guarantees a hex prefix but still allows odd-length or empty strings at compile time.
If you want to avoid malformed scripts slipping through, add a branded type or a runtime assertion:

type HexString<T extends string = string> = `0x${T}` & { readonly __hexBrand: unique symbol };

function assertEvenLengthHex(value: string): asserts value is HexString {
  if (!/^0x([0-9a-fA-F]{2})+$/.test(value)) {
    throw new Error('outputScript must be 0x-prefixed and byte-aligned');
  }
}
sdk/src/gateway/client.ts (1)

680-699: Race-condition & gas optimisation opportunity in allowance flow

Calling approve every time amount > allowance can front-run the create-order tx and wastes gas if another approval is inflight.
Optionally check pending allowance via publicClient.getTransactionCount or ask users to provide a max-approval upfront to skip the second RPC round-trip.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between 0264660 and 918840c.

📒 Files selected for processing (12)
  • sdk/src/gateway/client.ts (13 hunks)
  • sdk/src/gateway/strategy.ts (4 hunks)
  • sdk/src/gateway/tokens.ts (2 hunks)
  • sdk/src/gateway/types.ts (3 hunks)
  • sdk/src/inscription.ts (1 hunks)
  • sdk/src/ordinal-api/index.ts (1 hunks)
  • sdk/src/ordinals/commit.ts (1 hunks)
  • sdk/src/ordinals/index.ts (1 hunks)
  • sdk/src/wallet/utxo.ts (3 hunks)
  • sdk/test/gateway.test.ts (5 hunks)
  • sdk/test/ordinal-api.test.ts (3 hunks)
  • sdk/tsconfig.json (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
sdk/test/ordinal-api.test.ts (1)
sdk/src/ordinal-api/index.ts (1)
  • OutputJson (116-177)
sdk/src/gateway/types.ts (1)
sdk/src/gateway/abi.ts (1)
  • strategyCaller (3-39)
🔇 Additional comments (19)
sdk/src/ordinal-api/index.ts (1)

143-146: LGTM! Well-documented property addition.

The confirmations property has been properly added to the OutputJson interface with appropriate JSDoc documentation. This enriches the output data structure with valuable confirmation count information.

sdk/test/ordinal-api.test.ts (3)

2-2: LGTM! Appropriate import update.

Import statement correctly updated to include expect from vitest, which is used later in the test file.


73-73: LGTM! Effective type adaptation.

Good use of TypeScript's Omit utility type to exclude the newly added confirmations property from the expected test object, avoiding the need to update the test fixture.


85-85: LGTM! Improved assertion approach.

Excellent change from assert.deepStrictEqual to expect(...).toMatchObject(...), which allows for partial matching rather than requiring exact equality. This handles the addition of the confirmations property in the actual response without having to specify it in the test expectations.

sdk/src/inscription.ts (1)

44-44: Improved null safety for the body property

Excellent change! Adding Buffer.alloc(0) as a fallback ensures that this.body is always initialized with a valid Buffer instance, even when no body argument is provided. This is particularly important for strict null checks.

sdk/tsconfig.json (1)

15-15: Great addition of strictNullChecks

This compiler option enhances type safety by detecting potential null/undefined errors at compile time. This is a positive step toward more robust code and aligns perfectly with the other null-safety improvements in this PR.

sdk/src/ordinals/index.ts (1)

30-30: Safer handling of tapLeafScript in PSBT construction

This improvement ensures that tapLeafScript is only wrapped in an array when it exists, preventing the passing of arrays with undefined values. This change is essential for proper PSBT construction and aligns well with the new strict null checks.

sdk/src/ordinals/commit.ts (2)

43-43: Modern and safer array access

Using .at(-1) is a more modern and readable way to access the last element of an array compared to manual index calculation. This also adds optional chaining for better null safety.


48-48: Enhanced null safety for controlBlock

Adding Buffer.alloc(0) as a fallback ensures the controlBlock is always a valid Buffer, even when cblock is null or undefined. This is important for consistent behavior and aligns with the strictNullChecks compiler option.

sdk/src/gateway/tokens.ts (1)

372-386: Well-implemented token address resolution function

This new function centralizes token address resolution logic, which improves code maintainability. It properly handles both addresses and symbols, and has clear error handling.

Two minor suggestions for improvement:

  1. Add JSDoc comments to document the parameters and return value
  2. Consider normalizing the input token string to lowercase for more consistent lookups when it's a symbol
/**
 * Resolves a token symbol or address to its canonical address for a given chain
 * @param chain The chain ID or name
 * @param toToken The token symbol or address
 * @returns The resolved token address
 * @throws Error if the token cannot be resolved
 */
export function getTokenAddress(chain: string | number, toToken: string): Address {
    const isMainnet = chain === ChainId.BOB || (typeof chain === 'string' && chain.toLowerCase() === Chain.BOB);
    const isTestnet =
        chain === ChainId.BOB_SEPOLIA || (typeof chain === 'string' && chain.toLowerCase() === Chain.BOB_SEPOLIA);

    if (isAddress(toToken)) {
        return toToken;
-    } else if (isMainnet && SYMBOL_LOOKUP[chain][toToken]) {
+    } else if (isMainnet && SYMBOL_LOOKUP[chain][toToken.toLowerCase()]) {
-        return SYMBOL_LOOKUP[chain][toToken].address;
+        return SYMBOL_LOOKUP[chain][toToken.toLowerCase()].address;
-    } else if (isTestnet && SYMBOL_LOOKUP[chain][toToken]) {
+    } else if (isTestnet && SYMBOL_LOOKUP[chain][toToken.toLowerCase()]) {
-        return SYMBOL_LOOKUP[chain][toToken].address;
+        return SYMBOL_LOOKUP[chain][toToken.toLowerCase()].address;
    } else {
        throw new Error('Unknown output token');
    }
}
sdk/test/gateway.test.ts (4)

709-764: Good test implementation for new executeQuote method

The test properly verifies the behavior of the new executeQuote method for onramp quotes. It mocks the necessary responses, spies on the relevant methods, and asserts the expected result.

The test covers:

  1. Proper setup of mocks and test data
  2. Calling the executeQuote method with correct parameters
  3. Verifying that startOrder and finalizeOrder are called
  4. Asserting that a Bitcoin transaction ID is returned

This ensures that the new functionality is properly tested.


561-561: Parameter naming updated from bitcoinUserAddress to toUserAddress

This change aligns with the overall API improvement in the PR to make parameter naming more consistent.


650-650: Parameter naming updated from bitcoinUserAddress to toUserAddress

This change aligns with the overall API improvement in the PR to make parameter naming more consistent.


660-660: Updated mock response format for offramp registry address

The mock response is now a raw string instead of a JSON string, matching the updated API response format.

sdk/src/wallet/utxo.ts (2)

108-108: Made publicKey parameter optional with sensible default for isSignet

This change improves the API by making the publicKey parameter optional and providing a default value for isSignet. This increases flexibility while maintaining backward compatibility.


370-370: Updated return type to allow undefined

The return type now correctly includes undefined as a possible return value, which improves type safety.

sdk/src/gateway/types.ts (2)

50-53: Typed strategyFunctionName is a welcome safety improvement

Referencing the name directly from strategyCaller ((typeof strategyCaller)[number]['name']) eliminates stringly-typed errors at compile-time.


444-449: Nullable tx hashes enhance clarity

Marking submitOrderEvmTx and btcTx as string | null explicitly communicates that these fields may be absent—nice improvement for consumers.

sdk/src/gateway/client.ts (1)

189-195: Potential undefined look-ups in ADDRESS_LOOKUP

ADDRESS_LOOKUP[this.chainId][quote.baseTokenAddress] (and the output-token line below) will throw if either lookup is missing.
Consider defensive fallback logic or a clear error so the SDK fails gracefully when token metadata is incomplete.

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 comments (1)
sdk/test/gateway.test.ts (1)

651-654: ⚠️ Potential issue

Add error handling for undefined psbtBase64

The code uses a non-null assertion (psbtBase64!) without verifying that the value exists. This could lead to runtime errors if startOrder doesn't return a PSBT.

-const bitcoinTxHex = await btcSigner.signAllInputs(psbtBase64!);
+if (!psbtBase64) {
+  throw new Error('No PSBT was created. Check if startOrder was successful.');
+}
+const bitcoinTxHex = await btcSigner.signAllInputs(psbtBase64);
♻️ Duplicate comments (3)
sdk/src/gateway/client.ts (3)

193-196: ⚠️ Potential issue

Missing error handling in fetchOfframpRegistryAddress

The method doesn't check if the HTTP response was successful before parsing the result, which can lead to unexpected behavior with error responses.

async fetchOfframpRegistryAddress(): Promise<Address> {
    const response = await this.fetchGet(`${this.baseUrl}/offramp-registry-address`);
-   return response.text() as Promise<Address>;
+   if (!response.ok) {
+     const message = await response.text().catch(() => 'Failed to fetch offramp registry address');
+     throw new Error(`Offramp registry API error: ${message}`);
+   }
+   return (await response.text()) as Address;
}

651-652: ⚠️ Potential issue

Missing null check before using psbtBase64

The code uses the non-null assertion operator (!) on psbtBase64 without first checking if it exists. This could cause runtime errors if startOrder doesn't return a valid PSBT.

-const bitcoinTxHex = await btcSigner.signAllInputs(psbtBase64!);
+if (!psbtBase64) {
+  throw new Error('startOrder did not return a PSBT. Ensure fromChain is "bitcoin" and wallet connector is configured.');
+}
+const bitcoinTxHex = await btcSigner.signAllInputs(psbtBase64);

749-759: ⚠️ Potential issue

Improve getFinal function to handle undefined values

The getFinal function uses type assertions to force the type checker to treat potentially undefined values as non-nullable, which could lead to runtime errors.

-function getFinal<L, R>(base?: L, output?: R): NonNullable<L | R> {
-    return order.status
-        ? order.strategyAddress
-            ? output
-                ? output
-                : (base as NonNullable<typeof base>)
-            : (base as NonNullable<typeof base>)
-        : order.strategyAddress
-          ? (output as NonNullable<typeof output>)
-          : (base as NonNullable<typeof base>);
+function getFinal<L, R>(base: L | undefined, output: R | undefined): NonNullable<L | R> {
+  const result =
+    order.status
+      ? order.strategyAddress
+        ? output ?? base
+        : base
+      : order.strategyAddress
+        ? output
+        : base;
+
+  if (result === undefined) {
+    throw new Error('Missing token address/amount in order payload');
+  }
+  return result as NonNullable<L | R>;
}
🧹 Nitpick comments (3)
sdk/test/gateway.test.ts (1)

767-780: Consider typing the mock objects more precisely

The mock objects for walletClient and publicClient are cast using as unknown as which bypasses type checking. Consider creating properly typed mocks.

-const walletClient = {
+// Create a properly typed mock
+const walletClient = {
  writeContract: () => Promise.resolve('0x35f5bca7f984f4ed97888944293b979f3abb198a5716d04e10c6bdc023080075'),
-} as unknown as Parameters<typeof gatewaySDK.executeQuote>[2];
+} satisfies Partial<WalletClient<Transport, ViemChain, Account>> as Parameters<typeof gatewaySDK.executeQuote>[2];
sdk/src/gateway/client.ts (2)

590-601: Better error handling for PSBT creation

The code now throws a specific error message when the PSBT creation fails, which will make debugging easier. However, the function could be improved by clarifying the return type in the JSDoc.

/**
 * Start an order via the Gateway API to reserve liquidity. This is step 1 of 2, see the {@link finalizeOrder} method.
 *
 * @param gatewayQuote The quote given by the {@link getQuote} method.
 * @param params The parameters for the quote, same as before.
+ * @returns {Promise<GatewayStartOrder & { psbtBase64?: string }>} Success object with PSBT if fromChain is Bitcoin.
 */

777-778: Consider adding null check for outputToken

The property access for order.outputTokenAddress! uses a non-null assertion without a check, which could lead to runtime errors.

-outputToken: ADDRESS_LOOKUP[chainId][order.outputTokenAddress!],
+outputToken: order.outputTokenAddress ? ADDRESS_LOOKUP[chainId][order.outputTokenAddress] : undefined,
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between 918840c and daf2624.

📒 Files selected for processing (3)
  • sdk/src/gateway/client.ts (15 hunks)
  • sdk/src/gateway/tokens.ts (3 hunks)
  • sdk/test/gateway.test.ts (5 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • sdk/src/gateway/tokens.ts
🧰 Additional context used
🧬 Code Graph Analysis (2)
sdk/test/gateway.test.ts (3)
sdk/src/gateway/client.ts (1)
  • MAINNET_GATEWAY_BASE_URL (60-60)
sdk/src/gateway/types.ts (2)
  • GatewayQuote (220-237)
  • GatewayTokensInfo (336-341)
sdk/src/gateway/tokens.ts (1)
  • getTokenAddress (384-398)
sdk/src/gateway/client.ts (3)
sdk/src/gateway/tokens.ts (1)
  • getTokenAddress (384-398)
sdk/src/gateway/types.ts (4)
  • OfframpCreateOrderParams (385-405)
  • GatewayQuote (220-237)
  • GatewayTokensInfo (336-341)
  • GatewayQuoteParams (91-128)
sdk/src/wallet/utxo.ts (1)
  • getAddressInfo (22-24)
🪛 Gitleaks (8.26.0)
sdk/test/gateway.test.ts

558-558: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.

(generic-api-key)


647-647: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.

(generic-api-key)

🔇 Additional comments (11)
sdk/test/gateway.test.ts (4)

1-7: Good addition of necessary imports

The imports added are appropriate for the new functionality being tested, including bitcoin-js, viem utilities, and Ethereum's ZeroAddress.


709-721: Good test setup for the new executeQuote onramp feature

This test properly sets up the testing environment with a mock BTC signer and spies on the internal methods that should be called during execution.


817-820: Good test validation for offramp flow

The test correctly verifies the transaction hash is returned and that the expected methods are called exactly once.


558-558: False positive from static analysis for API keys

The static analysis tool flagged these lines as containing API keys, but these are just token addresses used in tests.

Also applies to: 647-647

🧰 Tools
🪛 Gitleaks (8.26.0)

558-558: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.

(generic-api-key)

sdk/src/gateway/client.ts (7)

32-48: Good import organization

The imports have been properly organized, with the addition of necessary viem utilities and types for contract interactions.


157-158: Improved token address handling with centralized function

The code now uses the centralized getTokenAddress helper function instead of duplicating the logic in multiple places, which is a good refactoring.

Also applies to: 302-303


263-264: Improved error message in fetchOfframpQuote

The error message now includes the query parameters, which will make debugging easier.


328-329: Improved type safety for outputScript

The explicit type definition for outputScript as a hex-prefixed string improves type safety.


615-700: Well-implemented executeQuote method

The new executeQuote method provides a unified API for both onramp and offramp flows. It handles token approvals, contract interactions, and transaction monitoring, which is a great addition.


1034-1042: Simplified fetchGet implementation

Removing the unnecessary await in fetchGet is a good cleanup. The function now correctly returns the Promise directly.


1102-1105: Good helper function for creating viem clients

The viemClient function is a good abstraction that centralizes the creation of viem clients, which promotes code reuse.

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

♻️ Duplicate comments (2)
sdk/src/gateway/client.ts (2)

197-200: Missing response.ok guard repeats an earlier issue

The method still returns response.text() without verifying response.ok. A 4xx/5xx will silently propagate garbage data and break downstream logic – exactly the problem raised in the previous review.


818-828: getFinal still risks returning undefined

The earlier feedback about replacing type-assertions with explicit checks hasn’t been addressed; the helper can still emit undefined at runtime. Please revisit the suggested refactor or add a runtime guard.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between d84c23b and b75cb2b.

📒 Files selected for processing (4)
  • sdk/src/gateway/client.ts (19 hunks)
  • sdk/src/gateway/types.ts (4 hunks)
  • sdk/src/ordinal-api/index.ts (1 hunks)
  • sdk/test/ordinal-api.test.ts (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • sdk/test/ordinal-api.test.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • sdk/src/ordinal-api/index.ts
  • sdk/src/gateway/types.ts
🔇 Additional comments (1)
sdk/src/gateway/client.ts (1)

665-668: 🛠️ Refactor suggestion

Unnecessary non-null assertion & unclear error message

startOrder already guarantees psbtBase64 is defined or throws, so ! is redundant and hides future regressions.
Additionally, the follow-up error 'no psbt' is vague.

-const bitcoinTxHex = await btcSigner.signAllInputs(psbtBase64!);
-
-if (!bitcoinTxHex) throw new Error('no psbt');
+const bitcoinTxHex = await btcSigner.signAllInputs(psbtBase64);
+
+if (!bitcoinTxHex)
+  throw new Error('Failed to sign PSBT – wallet connector returned empty hex.');

Likely an incorrect or invalid review comment.

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

♻️ Duplicate comments (3)
sdk/src/gateway/client.ts (3)

197-200: fetchOfframpRegistryAddress still ignores HTTP errors

This method doesn't check response.ok before calling text(), unlike other API methods in this file. This could result in returning error responses as valid addresses.

-const response = await this.fetchGet(`${this.baseUrl}/offramp-registry-address`);
-return response.text() as Promise<Address>;
+const response = await this.fetchGet(`${this.baseUrl}/offramp-registry-address`);
+if (!response.ok) {
+  const errorMessage = await response.text() || 'Failed to fetch registry address';
+  throw new Error(`Offramp registry API error: ${errorMessage}`);
+}
+return (await response.text()) as Address;

818-828: getFinal still has type safety issues

This function still uses type assertions without proper runtime checks, which could lead to undefined values at runtime.

-function getFinal<L, R>(base?: L, output?: R): NonNullable<L | R> {
-    return order.status
-        ? order.strategyAddress
-            ? output
-                ? output // success
-                : (base as NonNullable<typeof base>) // failed
-            : (base as NonNullable<typeof base>) // success
-        : order.strategyAddress // pending
-          ? (output as NonNullable<typeof output>)
-          : (base as NonNullable<typeof base>);
+function getFinal<L, R>(base: L | undefined, output: R | undefined): NonNullable<L | R> {
+  const result = order.status
+    ? order.strategyAddress
+      ? output ?? base
+      : base
+    : order.strategyAddress
+      ? output
+      : base;
+
+  if (result === undefined) {
+    throw new Error('Missing token address/amount in order payload');
+  }
+  return result as NonNullable<L | R>;
+}

607-769: ⚠️ Potential issue

New unified executeQuote method implementation

This method provides a high-level interface that handles the full flow of executing quotes, including onramp, offramp, and staking operations.

However, there are a few issues that need to be addressed:

  1. On line 667, you're using a non-null assertion (psbtBase64!) without first checking if it exists.
  2. The stateOverride parameter (lines 750-761) has an incorrect structure for viem's API.
-const bitcoinTxHex = await btcSigner.signAllInputs(psbtBase64!);
+if (!psbtBase64) {
+  throw new Error('PSBT not created. Ensure fromChain is Bitcoin and parameters are correct.');
+}
+const bitcoinTxHex = await btcSigner.signAllInputs(psbtBase64);
-stateOverride: [
-    // overriding token allowance
-    {
-        address: order.params.token,
-        stateDiff: [
-            {
-                slot: allowanceSlot,
-                value: maxAllowance,
-            },
-        ],
-    },
-],
+stateOverride: {
+    [order.params.token]: {
+        storageDiff: {
+            [allowanceSlot]: maxAllowance,
+        },
+    },
+},
🧹 Nitpick comments (1)
sdk/src/gateway/client.ts (1)

669-669: Redundant null check after await

This check for bitcoinTxHex is executed after awaiting the promise. If signAllInputs fails, an exception would be thrown before reaching this line, making this check redundant.

-if (!bitcoinTxHex) throw new Error('no psbt');
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between b75cb2b and 405299c.

📒 Files selected for processing (5)
  • sdk/src/gateway/client.ts (24 hunks)
  • sdk/src/gateway/index.ts (1 hunks)
  • sdk/src/gateway/types.ts (9 hunks)
  • sdk/src/ordinal-api/index.ts (1 hunks)
  • sdk/test/gateway.test.ts (15 hunks)
✅ Files skipped from review due to trivial changes (1)
  • sdk/src/gateway/index.ts
🚧 Files skipped from review as they are similar to previous changes (3)
  • sdk/src/ordinal-api/index.ts
  • sdk/test/gateway.test.ts
  • sdk/src/gateway/types.ts
🔇 Additional comments (10)
sdk/src/gateway/client.ts (10)

32-32: Improved token address resolution with centralized helper

The getTokenAddress function from tokens.ts has been properly imported and used in place of manual token address resolution logic, making the code more maintainable.


161-162: Using centralized token resolution function

Good refactoring to use the dedicated getTokenAddress function instead of duplicating token address resolution logic.


267-267: Improved error reporting

Good improvement to include query parameters in the error message, making debugging easier.


306-307: Using centralized token address resolution

Good refactoring to use the dedicated getTokenAddress function for consistent token resolution.


332-333: Added explicit type casting for output script

The type cast to 0x${string} ensures the output script is properly typed as a hex string, improving type safety.


429-430: Standardized timestamp handling

Changed orderTimestamp from bigint to number for consistent timestamp handling across the codebase.

Also applies to: 440-440


594-604: Improved error handling for failed PSBT creation

Better structured return statement and clearer error message for when Bitcoin PSBT creation fails.


1104-1113: Added aggregated orders method

Great addition! This method provides a convenient way to fetch both onramp and offramp orders in a single call.


1115-1123: Extracted common fetch pattern

Good refactoring to extract the common fetch GET pattern to reduce duplication.


1183-1186: Added helper for creating viem clients

Good abstraction to centralize the client creation logic based on the chain.

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

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

785-798: Consider adding more comprehensive error testing.

While the happy path for offramp execution is tested, consider adding test cases for error scenarios such as:

  1. Insufficient allowance
  2. Contract execution failures
  3. Network errors during API calls

This would improve the robustness of the test suite and ensure proper error handling in the implementation.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between 55ff3ae and 6f71e0d.

📒 Files selected for processing (2)
  • sdk/src/gateway/tokens.ts (2 hunks)
  • sdk/test/gateway.test.ts (15 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • sdk/src/gateway/tokens.ts
🧰 Additional context used
🪛 GitHub Actions: SDK
sdk/test/gateway.test.ts

[error] 61-61: Test failure: 'Gateway Tests > should return evm txid for offramp' failed with error 'Cannot cast mainnet to non-mainnet'. Stack trace includes castTestnetTo at bitcoin-address-validation/src/index.ts:61:11.

🔇 Additional comments (12)
sdk/test/gateway.test.ts (12)

1-7: Organized imports with proper type modules.

The imports have been reorganized and expanded to include additional libraries and types such as bitcoinjs-lib, ethers' ZeroAddress, nock, and various utilities from viem, which aligns with the new requirements for the executeQuote functionality.


10-10: New token utility imports added.

The addition of getTokenAddress and SYMBOL_LOOKUP imports is appropriate for the new token address resolution functionality needed by the executeQuote method.


12-17: Updated type imports for enhanced type safety.

The type imports have been updated to include new types and refinements:

  • BuildStakeParams has been replaced with StakeParams
  • Added GatewayQuote, GatewayTokensInfo, and OfframpOrder

These changes reflect the type refinements made in the gateway types file and improve type safety.


345-345: Method name changed to be more specific.

The method call was changed from getOrders to getOnrampOrders, aligning with the new specialized order retrieval methods added in the client implementation.


558-559: Parameter names corrected to match updated method signatures.

The parameter names were appropriately corrected from toToken to fromToken and from bitcoinUserAddress to toUserAddress to match the updated method signatures in the client implementation.

Also applies to: 561-562


588-588: Type changes for orderTimestamp from BigInt to number.

The type assertions for orderTimestamp were changed from BigInt to number to reflect the type changes in OfframpOrder and related types in the types file.

Also applies to: 600-600


616-616: New method for retrieving offramp orders.

The implementation now correctly uses the dedicated getOfframpOrders method, which provides better separation of concerns for different order types.


660-660: API response format updated.

The API response format has been updated to return a plain string rather than a JSON string that needs to be parsed.


669-670: Timestamp handling updated to use seconds.

The timestamp handling now correctly uses seconds since epoch (standard Unix timestamp) with Math.floor(Date.now() / 1000), which aligns with the requirements for order timestamp processing.


709-764: New test case for executing an onramp quote.

This test verifies that executing an onramp quote returns a Bitcoin transaction ID by properly mocking:

  • Order creation
  • Bitcoin signer functionality
  • Order finalization HTTP calls

The test is well-structured and covers the core functionality of the onramp flow.


822-858: New test case for executing a stake quote.

This test verifies that executing a stake quote returns an EVM transaction ID by mocking contract interactions and staking parameter building. The test case provides good coverage for the stake flow in the executeQuote method.


860-875: New test for the aggregated getOrders method.

This test verifies that the new getOrders method correctly calls both getOnrampOrders and getOfframpOrders and returns combined results. The test uses appropriate spies to verify that both underlying methods are called.

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

♻️ Duplicate comments (4)
sdk/src/gateway/client.ts (4)

825-835: 🛠️ Refactor suggestion

Improve safety of getFinal function

The getFinal function uses type assertions without runtime checks, which could lead to undefined values at runtime.

-function getFinal<L, R>(base?: L, output?: R): NonNullable<L | R> {
-    return order.status
-        ? order.strategyAddress
-            ? output
-                ? output // success
-                : (base as NonNullable<typeof base>) // failed
-            : (base as NonNullable<typeof base>) // success
-        : order.strategyAddress // pending
-          ? (output as NonNullable<typeof output>)
-          : (base as NonNullable<typeof base>);
+function getFinal<L, R>(base: L | undefined, output: R | undefined): NonNullable<L | R> {
+    const result =
+      order.status
+        ? order.strategyAddress
+          ? output ?? base
+          : base
+        : order.strategyAddress
+          ? output
+          : base;
+
+    if (result === undefined) {
+      throw new Error('Missing token address/amount in order payload');
+    }
+    return result as NonNullable<L | R>;
+}

214-217: ⚠️ Potential issue

Missing error response handling in fetchOfframpRegistryAddress

The method calls response.text() unconditionally without checking if the response was successful. If the API returns a 4xx or 5xx error, it will attempt to parse the error response as an address.

async fetchOfframpRegistryAddress(): Promise<Address> {
    const response = await this.fetchGet(`${this.baseUrl}/offramp-registry-address`);
+   if (!response.ok) {
+       const errorMessage = await response.text().catch(() => 'Failed to fetch registry address');
+       throw new Error(`Offramp registry API error: ${errorMessage}`);
+   }
    return response.text() as Promise<Address>;
}

690-692: ⚠️ Potential issue

Missing null check before using non-null assertion

The code uses psbtBase64! without verifying that it's defined, which could cause a runtime error.

-const bitcoinTxHex = await btcSigner.signAllInputs(psbtBase64!);
-
-if (!bitcoinTxHex) throw new Error('no psbt');
+if (!psbtBase64) {
+    throw new Error('Failed to obtain PSBT from startOrder. Ensure fromChain is "bitcoin" and wallet is configured correctly.');
+}
+const bitcoinTxHex = await btcSigner.signAllInputs(psbtBase64);
+
+if (!bitcoinTxHex) throw new Error('Failed to sign PSBT. The signer returned an empty transaction.');

745-745: ⚠️ Potential issue

Potential undefined reference to wallet account address

The code accesses walletClient.account.address without checking if account or address is defined.

-args: [walletClient.account.address as Address, result.strategyAddress],
+if (!walletClient.account?.address) {
+    throw new Error('Wallet client account address is not defined');
+}
+args: [walletClient.account.address as Address, result.strategyAddress],
🧹 Nitpick comments (2)
sdk/src/gateway/client.ts (2)

621-628: Improved error handling for PSBT creation

The enhanced error handling for PSBT creation is good, but the code path could be simplified further.

-if (!psbtBase64) {
-    throw new Error(
-        'Failed to create bitcoin psbt. Please check `fromChain` and `fromUserAddress` parameters.'
-    );
-}
-
-throw new Error('Failed to create bitcoin psbt due to an unexpected error.');
+throw new Error(
+    psbtBase64 
+        ? 'Failed to create bitcoin psbt due to an unexpected error.' 
+        : 'Failed to create bitcoin psbt. Please check `fromChain` and `fromUserAddress` parameters.'
+);

711-723: Duplicate token approval logic

The token allowance check and approval logic is duplicated for both offramp and stake paths.

Consider extracting this into a helper method:

private async ensureTokenAllowance(
    tokenAddress: Address,
    spenderAddress: Address,
    amount: bigint,
    walletClient: WalletClient<Transport, ViemChain, Account>,
    publicClient: PublicClient<Transport>
): Promise<void> {
    const allowance = await publicClient.readContract({
        address: tokenAddress,
        abi: erc20Abi,
        functionName: 'allowance',
        args: [walletClient.account.address as Address, spenderAddress],
    });

    if (amount > allowance) {
        const { request } = await publicClient.simulateContract({
            account: walletClient.account,
            address: tokenAddress,
            abi: erc20Abi,
            functionName: 'approve',
            args: [spenderAddress, MaxUint256],
        });

        const approveTxHash = await walletClient.writeContract(request);
        await publicClient.waitForTransactionReceipt({ hash: approveTxHash });
    }
}

Then call it in both places:

await this.ensureTokenAllowance(
    tokenAddress,
    offrampRegistryAddress,
    BigInt(order.params.amount),
    walletClient,
    publicClient
);

// And later for staking:
await this.ensureTokenAllowance(
    order.params.token,
    result.strategyAddress,
    BigInt(order.params.amount),
    walletClient,
    publicClient
);

Also applies to: 748-760

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 82f397e and e6a977e.

📒 Files selected for processing (1)
  • sdk/src/gateway/client.ts (25 hunks)
🔇 Additional comments (5)
sdk/src/gateway/client.ts (5)

323-326: Improved token address resolution

Good job using the new getTokenAddress utility function to consistently resolve token addresses.


137-206: Well-structured discriminated union for quote handling

The refactored getQuote method with discriminated union types provides a clean API for handling both onramp and offramp quotes. The separation of concerns between onramp and offramp logic improves readability.


1110-1127: Well-implemented order aggregation method

The new getOrders method effectively combines both onramp and offramp orders with proper type discrimination, making it easier for clients to handle different order types uniformly.


1082-1084: Improved error message with context

Adding the serialized strategies list to the error message is helpful for debugging when a strategy is not found.


644-686: Well-designed method signature for executeQuote

The executeQuote method has a comprehensive type definition that clearly separates the different quote types and their specific parameters. The discriminated union pattern makes the API both type-safe and intuitive.

* fix: overload getQuote method

* chore: merge types for get quote

---------

Co-authored-by: Slava <slava@interlay.io>
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

♻️ Duplicate comments (5)
sdk/test/gateway.test.ts (2)

794-809: Fix Bitcoin address in Signet offramp test

The test is using a mainnet Bitcoin address (bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq) with the Signet test network, which will cause validation to fail. This was previously flagged in pipeline failures.


850-889: ⚠️ Potential issue

Account property needed in mockWalletClient for stake execution

The mockWalletClient in the stake execution test needs an account property with an address field that the executeQuote method will access.

Apply this diff to add the missing account property:

const mockWalletClient = {
+    account: {
+        address: zeroAddress,
+    },
    writeContract: () => Promise.resolve('0x35f5bca7f984f4ed97888944293b979f3abb198a5716d04e10c6bdc023080075'),
} as unknown as Parameters<typeof gatewaySDK.executeQuote>[2];
sdk/src/gateway/client.ts (3)

218-221: ⚠️ Potential issue

Add response status check in fetchOfframpRegistryAddress

The method doesn't check if the response is successful before parsing the text, which could lead to unexpected behavior if the request fails.

async fetchOfframpRegistryAddress(): Promise<Address> {
    const response = await this.fetchGet(`${this.baseUrl}/offramp-registry-address`);
+   if (!response.ok) {
+       const message = await response.text().catch(() => 'Failed to fetch registry address');
+       throw new Error(`Offramp registry API error: ${message}`);
+   }
    return response.text() as Promise<Address>;
}

694-694: ⚠️ Potential issue

Add null check before using psbtBase64 in executeQuote

The code uses a non-null assertion (!) with psbtBase64 without verifying its presence, which can cause runtime errors if undefined.

-const bitcoinTxHex = await btcSigner.signAllInputs(psbtBase64!);
+if (!psbtBase64) {
+    throw new Error('startOrder did not return a PSBT. Ensure fromChain is "bitcoin" and wallet connector is configured.');
+}
+const bitcoinTxHex = await btcSigner.signAllInputs(psbtBase64);

748-750: ⚠️ Potential issue

Verify account.address is defined before accessing

The code accesses walletClient.account.address without checking if it exists, which could lead to runtime errors.

+if (!walletClient.account?.address) {
+    throw new Error('Wallet client account address is not defined');
+}
const allowance = await publicClient.readContract({
    address: order.params.token,
    abi: erc20Abi,
    functionName: 'allowance',
    args: [walletClient.account.address as Address, result.strategyAddress],
});
🧹 Nitpick comments (2)
sdk/test/gateway.test.ts (1)

908-957: Consider removing console.log statements from tests

The test includes console.log statements that print object keys, which may pollute test output.

-    console.log('Type keys offramp:', Object.keys(result_onramp));

-    console.log('Type keys offramp:', Object.keys(result_offramp));
sdk/src/gateway/client.ts (1)

288-288: Remove query parameters from error message to prevent potential data leakage

The error message includes the query parameters, which might leak sensitive information in logs.

-throw new Error(`Offramp API Error: ${errorMessage} ${queryParams}`);
+throw new Error(`Offramp API Error: ${errorMessage}`);
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e6a977e and 0b15751.

📒 Files selected for processing (2)
  • sdk/src/gateway/client.ts (29 hunks)
  • sdk/test/gateway.test.ts (23 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
sdk/test/gateway.test.ts (3)
sdk/src/gateway/types.ts (4)
  • StakeParams (26-39)
  • OfframpOrder (430-451)
  • GatewayQuote (218-235)
  • GatewayTokensInfo (334-339)
sdk/src/gateway/client.ts (2)
  • MAINNET_GATEWAY_BASE_URL (60-60)
  • SIGNET_GATEWAY_BASE_URL (72-72)
sdk/src/gateway/tokens.ts (1)
  • getTokenAddress (372-386)
🔇 Additional comments (7)
sdk/test/gateway.test.ts (3)

737-792: Good implementation of onramp quote execution test

The test properly validates the full flow of onramp quote execution, mocking the necessary components and verifying that both startOrder and finalizeOrder are called once.


794-848: Good implementation of offramp quote execution test

The test properly validates the full flow of offramp quote execution, including API calls, contract interactions, and transaction handling.


891-906: Good implementation of combined orders retrieval test

The test properly verifies that the new getOrders method calls both getOnrampOrders and getOfframpOrders and combines their results.

sdk/src/gateway/client.ts (4)

130-168: Well-structured overloaded getQuote method with discriminated union pattern

The refactored getQuote method using a discriminated union pattern with a type field provides better type safety and makes the API more explicit about what operation is being performed.


353-354: Good type safety improvement for outputScript

Using the more specific 0x${string} type for outputScript enhances type safety and makes the API more robust.


451-461: Good conversion of timestamps from bigint to number

Converting orderTimestamp from bigint to number is more appropriate for Unix timestamps and aligns with JavaScript's Date APIs.


1114-1131: Good implementation of unified orders retrieval

The new getOrders method efficiently combines results from both getOnrampOrders and getOfframpOrders into a single array with type discrimination.

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