Skip to content

Conversation

@PaulvanMotman
Copy link
Contributor

@PaulvanMotman PaulvanMotman commented Aug 8, 2025

This should fix the validation when denominating in ERC20 currencies on ton/starknet/aleo

Summary by CodeRabbit

  • New Features
    • Added support for TON, Starknet, and Aleo networks, including address validation and declarative chain entries.
    • Extended currency types to recognize TON, Starknet, and Aleo.
  • Tests
    • Added parameterized tests for request creation across non‑EVM networks and focused Aleo address validation tests.
  • Chores
    • Added runtime dependencies required for the new network validations.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 8, 2025

Walkthrough

Adds declarative chain support for TON, Starknet, and Aleo: new chain data files, updated declarative registry and types, address validation implementations in CurrencyManager, added runtime dependencies, and expanded tests (parameterized request-client tests and Aleo address unit tests).

Changes

Cohort / File(s) Change Summary
Dependency Updates
packages/currency/package.json
Added runtime dependencies: @ton/core@0.61.0, @ton/crypto@3.3.0, bech32@2.0.0, starknet@7.6.4.
Declarative Chain Data Files
packages/currency/src/chains/declarative/data/aleo.ts, packages/currency/src/chains/declarative/data/starknet.ts, packages/currency/src/chains/declarative/data/ton.ts
Added new files each exporting a chainId constant for Aleo, Starknet, and TON.
Declarative Chain Index
packages/currency/src/chains/declarative/index.ts
Imported and registered aleo, starknet, and ton in the declarative chains mapping.
Currency Manager Logic
packages/currency/src/currencyManager.ts
Added validateTonAddress, validateStarknetAddress, validateAleoAddress; extended validateAddress to route to them; added imports for @ton/core, starknet validator, and bech32.
Type Definitions
packages/types/src/currency-types.ts
Extended DeclarativeChainName type to include 'ton', 'starknet', and 'aleo'.
Tests — request client
packages/request-client.js/test/index.test.ts
Replaced single Solana test with parameterized tests for Solana, TON, Starknet, and Aleo declarative requests.
Tests — currency package
packages/currency/test/currencyManager.test.ts
Added unit tests for validateAleoAddress covering valid and invalid inputs, case variants, and edge cases.

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant CurrencyManager
    participant TONLib as @ton/core
    participant StarknetLib as starknet
    participant Bech32Lib as bech32

    Caller->>CurrencyManager: validateAddress(address, chainName)
    alt chainName == "ton"
        CurrencyManager->>TONLib: Address.parse(address)
        TONLib-->>CurrencyManager: success / throw
    else chainName == "starknet"
        CurrencyManager->>StarknetLib: validateAndParseAddress(address)
        StarknetLib-->>CurrencyManager: success / throw
    else chainName == "aleo"
        CurrencyManager->>Bech32Lib: decode(address) -> verify HRP === "aleo"
        Bech32Lib-->>CurrencyManager: decoded / throw
    else
        CurrencyManager-->>Caller: fallback existing validation flow
    end
    CurrencyManager-->>Caller: boolean (is valid)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~15 minutes

Possibly related PRs

Suggested reviewers

  • aimensahnoun
  • rodrigopavezi
  • alexandre-abrioux

📜 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 679e775 and 9c44bfb.

📒 Files selected for processing (2)
  • packages/currency/src/currencyManager.ts (3 hunks)
  • packages/currency/test/currencyManager.test.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/currency/test/currencyManager.test.ts
  • packages/currency/src/currencyManager.ts
⏰ 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: build-and-test
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/ton_address_validation

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.
  • 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.

Support

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

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 generate unit tests to generate unit tests for 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: 2

🧹 Nitpick comments (5)
packages/currency/src/chains/declarative/data/aleo.ts (1)

1-1: Good addition; consider typing the constant to enforce correctness at compile time.

Typing the constant prevents accidental typos and aligns with the declared union type.

+import type { DeclarativeChainName } from '@requestnetwork/types';
-export const chainId = 'aleo';
+export const chainId: DeclarativeChainName = 'aleo' as const;
packages/currency/src/chains/declarative/data/starknet.ts (1)

1-1: Add an explicit type for chainId for stronger type-safety.

Keeps literals aligned with DeclarativeChainName and avoids drift.

+import type { DeclarativeChainName } from '@requestnetwork/types';
-export const chainId = 'starknet';
+export const chainId: DeclarativeChainName = 'starknet' as const;
packages/currency/src/chains/declarative/data/ton.ts (1)

1-1: Type the chainId constant to match declared unions.

Consistent with other declarative chain data and prevents typos.

+import type { DeclarativeChainName } from '@requestnetwork/types';
-export const chainId = 'ton';
+export const chainId: DeclarativeChainName = 'ton' as const;
packages/request-client.js/test/index.test.ts (1)

1651-1703: Good parameterized coverage for non-EVM ERC20 declarative requests (Solana, TON, Starknet, Aleo).

Asserts align with ANY_DECLARATIVE behavior; keeps tests fast with mock storage.

Optionally add one negative case per new chain (invalid token address) to exercise the new validators directly.

packages/currency/src/currencyManager.ts (1)

328-340: Aleo address validator: confirm API name.

Many SDKs use from_string (as here) but some use fromString. If the API differs, this will always return false. Please confirm against the pinned SDK version.

If available, add a small unit test around validateAleoAddress with a known-good test vector.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 610eb5a and 8e1efc9.

⛔ Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (8)
  • packages/currency/package.json (1 hunks)
  • packages/currency/src/chains/declarative/data/aleo.ts (1 hunks)
  • packages/currency/src/chains/declarative/data/starknet.ts (1 hunks)
  • packages/currency/src/chains/declarative/data/ton.ts (1 hunks)
  • packages/currency/src/chains/declarative/index.ts (1 hunks)
  • packages/currency/src/currencyManager.ts (3 hunks)
  • packages/request-client.js/test/index.test.ts (2 hunks)
  • packages/types/src/currency-types.ts (1 hunks)
🧰 Additional context used
🧠 Learnings (45)
📓 Common learnings
Learnt from: MantisClone
PR: RequestNetwork/requestNetwork#1482
File: packages/payment-processor/src/payment/erc-20-private-payment-hinkal.ts:80-99
Timestamp: 2024-12-09T18:59:04.613Z
Learning: In the `RequestNetwork` codebase, payment processor functions such as `payErc20ProxyRequestFromHinkalShieldedAddress` in `packages/payment-processor/src/payment/erc-20-private-payment-hinkal.ts` should not include explicit request validation or try/catch blocks, and should rely on the underlying components (like `hinkalObject`) to handle error reporting.
Learnt from: aimensahnoun
PR: RequestNetwork/requestNetwork#1488
File: packages/payment-processor/src/payment/single-request-forwarder.ts:211-219
Timestamp: 2024-11-12T17:48:47.072Z
Learning: In `packages/payment-processor/src/payment/single-request-forwarder.ts`, the error handling logic in `payWithEthereumSingleRequestForwarder` is correct and does not require changes to differentiate between ERC20 and Ethereum SingleRequestForwarder contracts.
Learnt from: MantisClone
PR: RequestNetwork/requestNetwork#1482
File: packages/payment-processor/test/payment/erc-20-private-payment-hinkal.test.ts:38-38
Timestamp: 2024-12-18T03:53:54.370Z
Learning: In `packages/payment-processor/test/payment/erc-20-private-payment-hinkal.test.ts`, mainnet RPC is intentionally used for real on-chain tests as confirmed by MantisClone.
Learnt from: MantisClone
PR: RequestNetwork/requestNetwork#1482
File: packages/usage-examples/src/hinkal/hinkalRequestData.ts:0-0
Timestamp: 2024-12-04T05:01:13.722Z
Learning: In `packages/usage-examples/src/hinkal/hinkalRequestData.ts`, when integrating Hinkal, it's acceptable for the network to be set to 'base' as the payment chain while using the Sepolia gateway URL ('https://sepolia.gateway.request.network') as the request storage chain.
📚 Learning: 2024-11-22T13:30:25.703Z
Learnt from: rodrigopavezi
PR: RequestNetwork/requestNetwork#1475
File: packages/transaction-manager/test/unit/utils/test-data.ts:165-205
Timestamp: 2024-11-22T13:30:25.703Z
Learning: In `packages/transaction-manager/test/unit/utils/test-data.ts`, modifying `storedRawData` in the `FakeLitProtocolProvider` class may break existing functionality, so it should be left as is.

Applied to files:

  • packages/currency/src/chains/declarative/data/ton.ts
  • packages/currency/src/chains/declarative/data/starknet.ts
  • packages/currency/src/chains/declarative/data/aleo.ts
  • packages/types/src/currency-types.ts
  • packages/currency/src/chains/declarative/index.ts
  • packages/currency/src/currencyManager.ts
📚 Learning: 2024-11-04T14:31:29.664Z
Learnt from: giorgi-kiknavelidze
PR: RequestNetwork/requestNetwork#1482
File: packages/payment-processor/src/payment/prepared-transaction.ts:15-16
Timestamp: 2024-11-04T14:31:29.664Z
Learning: In `packages/payment-processor/src/payment/prepared-transaction.ts`, for the `IPreparedPrivateTransaction` interface, use `string[]` for the `ops` field since Hinkal's relevant functions accept arrays of `string` as inputs.

Applied to files:

  • packages/currency/src/chains/declarative/data/ton.ts
  • packages/types/src/currency-types.ts
  • packages/currency/src/chains/declarative/index.ts
  • packages/currency/src/currencyManager.ts
📚 Learning: 2024-11-05T16:58:18.471Z
Learnt from: MantisClone
PR: RequestNetwork/requestNetwork#1481
File: packages/payment-detection/test/provider.test.ts:25-25
Timestamp: 2024-11-05T16:58:18.471Z
Learning: In `provider.test.ts`, when testing `getDefaultProvider`, we use a chain that Infura supports but is not in our own RPC list (such as `maticmum`) to ensure that the function correctly falls back to `InfuraProvider`.

Applied to files:

  • packages/currency/src/chains/declarative/data/ton.ts
  • packages/currency/src/chains/declarative/data/starknet.ts
  • packages/types/src/currency-types.ts
  • packages/currency/src/chains/declarative/index.ts
📚 Learning: 2024-11-04T14:30:34.835Z
Learnt from: giorgi-kiknavelidze
PR: RequestNetwork/requestNetwork#1482
File: packages/usage-examples/src/hinkal/hinkalRequestData.ts:5-6
Timestamp: 2024-11-04T14:30:34.835Z
Learning: In `packages/usage-examples/src/hinkal/hinkalRequestData.ts`, it's acceptable to hardcode the USDC contract address without creating a mapping of USDC assets on specific networks.

Applied to files:

  • packages/currency/src/chains/declarative/data/starknet.ts
  • packages/currency/package.json
  • packages/currency/src/chains/declarative/index.ts
  • packages/currency/src/currencyManager.ts
  • packages/request-client.js/test/index.test.ts
📚 Learning: 2024-12-13T10:00:17.504Z
Learnt from: rodrigopavezi
PR: RequestNetwork/requestNetwork#1512
File: packages/integration-test/test/lit-protocol.test.ts:48-50
Timestamp: 2024-12-13T10:00:17.504Z
Learning: In `packages/integration-test/test/lit-protocol.test.ts`, the wallet private key `'0x7b595b2bb732edddc4d4fe758ae528c7a748c40f0f6220f4494e214f15c5bfeb'` is fixed and can be hardcoded in the test file.

Applied to files:

  • packages/currency/src/chains/declarative/data/starknet.ts
  • packages/currency/src/chains/declarative/data/aleo.ts
📚 Learning: 2024-12-04T05:01:13.722Z
Learnt from: MantisClone
PR: RequestNetwork/requestNetwork#1482
File: packages/usage-examples/src/hinkal/hinkalRequestData.ts:0-0
Timestamp: 2024-12-04T05:01:13.722Z
Learning: In `packages/usage-examples/src/hinkal/hinkalRequestData.ts`, when integrating Hinkal, it's acceptable for the network to be set to 'base' as the payment chain while using the Sepolia gateway URL ('https://sepolia.gateway.request.network') as the request storage chain.

Applied to files:

  • packages/currency/src/chains/declarative/data/starknet.ts
  • packages/currency/src/chains/declarative/data/aleo.ts
  • packages/currency/src/chains/declarative/index.ts
📚 Learning: 2024-12-18T03:53:54.370Z
Learnt from: MantisClone
PR: RequestNetwork/requestNetwork#1482
File: packages/payment-processor/test/payment/erc-20-private-payment-hinkal.test.ts:38-38
Timestamp: 2024-12-18T03:53:54.370Z
Learning: In `packages/payment-processor/test/payment/erc-20-private-payment-hinkal.test.ts`, mainnet RPC is intentionally used for real on-chain tests as confirmed by MantisClone.

Applied to files:

  • packages/currency/src/chains/declarative/data/starknet.ts
  • packages/request-client.js/test/index.test.ts
📚 Learning: 2024-11-04T12:18:18.615Z
Learnt from: giorgi-kiknavelidze
PR: RequestNetwork/requestNetwork#1482
File: packages/usage-examples/package.json:42-42
Timestamp: 2024-11-04T12:18:18.615Z
Learning: In the RequestNetwork project, the `dotenv` package version is maintained at `10.0.0` across packages, including `packages/smart-contracts/package.json`, to ensure consistency.

Applied to files:

  • packages/currency/src/chains/declarative/data/starknet.ts
  • packages/currency/package.json
📚 Learning: 2024-11-18T12:33:47.986Z
Learnt from: rodrigopavezi
PR: RequestNetwork/requestNetwork#1475
File: packages/epk-cypher/package.json:49-67
Timestamp: 2024-11-18T12:33:47.986Z
Learning: In the `packages/epk-cypher/package.json` file, avoid suggesting updates to development dependencies unless essential, as the maintainer prefers to prevent potential instability.

Applied to files:

  • packages/currency/package.json
📚 Learning: 2024-11-01T18:44:46.597Z
Learnt from: MantisClone
PR: RequestNetwork/requestNetwork#1481
File: packages/integration-test/package.json:60-60
Timestamp: 2024-11-01T18:44:46.597Z
Learning: In the RequestNetwork project, it's unnecessary to include dependency version information for ethers in the `README.md` of `packages/integration-test`, as the SDK user's package manager handles this.

Applied to files:

  • packages/currency/package.json
📚 Learning: 2024-11-04T12:18:12.407Z
Learnt from: giorgi-kiknavelidze
PR: RequestNetwork/requestNetwork#1482
File: packages/payment-processor/package.json:42-42
Timestamp: 2024-11-04T12:18:12.407Z
Learning: In the RequestNetwork project, dependencies in `package.json` files are pinned to exact versions to prevent unexpected breakages with examples. Therefore, caret version ranges (e.g., `^0.0.167`) should not be suggested.

Applied to files:

  • packages/currency/package.json
📚 Learning: 2024-11-12T16:52:41.557Z
Learnt from: aimensahnoun
PR: RequestNetwork/requestNetwork#1488
File: packages/smart-contracts/src/lib/artifacts/SingleRequestProxyFactory/index.ts:5-5
Timestamp: 2024-11-12T16:52:41.557Z
Learning: When the smart contracts are not being modified, types like `SingleRequestProxyFactory` in `packages/smart-contracts/src/lib/artifacts/SingleRequestProxyFactory/index.ts` should remain unchanged, even if terminology elsewhere in the code is updated.

Applied to files:

  • packages/currency/package.json
  • packages/types/src/currency-types.ts
  • packages/currency/src/chains/declarative/index.ts
📚 Learning: 2024-11-05T16:53:05.280Z
Learnt from: MantisClone
PR: RequestNetwork/requestNetwork#1481
File: packages/integration-test/test/scheduled/erc20-proxy.test.ts:0-0
Timestamp: 2024-11-05T16:53:05.280Z
Learning: In `packages/integration-test/test/scheduled/erc20-proxy.test.ts`, when upgrading dependencies like `ethers`, additional error handling test cases for contract interactions and provider errors may not be necessary.

Applied to files:

  • packages/currency/package.json
  • packages/request-client.js/test/index.test.ts
📚 Learning: 2024-12-06T10:32:50.647Z
Learnt from: rodrigopavezi
PR: RequestNetwork/requestNetwork#1510
File: .circleci/config.yml:0-0
Timestamp: 2024-12-06T10:32:50.647Z
Learning: It's acceptable to exclude the following packages from unit tests in CI: `requestnetwork/smart-contracts`, `requestnetwork/payment-detection`, `requestnetwork/payment-processor`, and `requestnetwork/integration-test`.

Applied to files:

  • packages/currency/package.json
  • packages/request-client.js/test/index.test.ts
📚 Learning: 2024-11-05T16:54:58.124Z
Learnt from: MantisClone
PR: RequestNetwork/requestNetwork#1481
File: packages/payment-processor/test/payment/utils.test.ts:113-113
Timestamp: 2024-11-05T16:54:58.124Z
Learning: The upgrade to `ethers` version 5.7.2 has been reverted, so suggestions dependent on features introduced in ethers 5.7.2 (such as `lastBaseFeePerGas` in `FeeData`) may not be applicable.

Applied to files:

  • packages/currency/package.json
📚 Learning: 2024-11-05T05:33:36.189Z
Learnt from: MantisClone
PR: RequestNetwork/requestNetwork#1478
File: packages/smart-contracts/scripts-create2/contract-setup/setupSingleRequestProxyFactory.ts:26-28
Timestamp: 2024-11-05T05:33:36.189Z
Learning: In the `requestNetwork` project's TypeScript setup scripts located in `packages/smart-contracts/scripts-create2/contract-setup`, `Promise.all` is used for asynchronous network setup tasks to maintain consistency across scripts.

Applied to files:

  • packages/currency/package.json
  • packages/currency/src/currencyManager.ts
📚 Learning: 2024-11-05T05:33:36.551Z
Learnt from: MantisClone
PR: RequestNetwork/requestNetwork#1478
File: packages/smart-contracts/scripts-create2/contract-setup/setupSingleRequestProxyFactory.ts:30-36
Timestamp: 2024-11-05T05:33:36.551Z
Learning: In the RequestNetwork project, admin scripts like `setupSingleRequestProxyFactory.ts` in `packages/smart-contracts/scripts-create2/contract-setup/` do not require extensive error checking.

Applied to files:

  • packages/currency/package.json
📚 Learning: 2024-11-04T12:17:27.070Z
Learnt from: giorgi-kiknavelidze
PR: RequestNetwork/requestNetwork#1482
File: packages/payment-processor/src/payment/prepared-transaction.ts:0-0
Timestamp: 2024-11-04T12:17:27.070Z
Learning: In TypeScript code, such as in `packages/payment-processor/src/payment/prepared-transaction.ts`, prefer not to add unnecessary type aliases when existing types like `string[]` suffice.

Applied to files:

  • packages/types/src/currency-types.ts
  • packages/currency/src/chains/declarative/index.ts
📚 Learning: 2024-11-22T13:13:26.166Z
Learnt from: rodrigopavezi
PR: RequestNetwork/requestNetwork#1475
File: packages/transaction-manager/test/unit/utils/test-data.ts:0-0
Timestamp: 2024-11-22T13:13:26.166Z
Learning: In `packages/transaction-manager/test/unit/utils/test-data.ts`, the `FakeLitProtocolProvider` class uses `{}` as the return type for its methods `encrypt` and `decrypt`. Changing the return type to a more specific interface caused issues, so the current return type `{}` should remain as is.

Applied to files:

  • packages/types/src/currency-types.ts
  • packages/currency/src/chains/declarative/index.ts
  • packages/currency/src/currencyManager.ts
  • packages/request-client.js/test/index.test.ts
📚 Learning: 2024-11-12T16:54:02.702Z
Learnt from: aimensahnoun
PR: RequestNetwork/requestNetwork#1488
File: packages/payment-processor/src/payment/single-request-forwarder.ts:104-104
Timestamp: 2024-11-12T16:54:02.702Z
Learning: In `packages/payment-processor/src/payment/single-request-forwarder.ts`, when the smart contract has not changed, event argument names such as `proxyAddress` remain the same, even if variable names in the code are updated to use new terminology like `forwarderAddress`.

Applied to files:

  • packages/types/src/currency-types.ts
  • packages/currency/src/chains/declarative/index.ts
  • packages/currency/src/currencyManager.ts
📚 Learning: 2024-10-28T20:00:33.707Z
Learnt from: MantisClone
PR: RequestNetwork/requestNetwork#1474
File: packages/smart-contracts/scripts/test-deploy-single-request-proxy.ts:4-7
Timestamp: 2024-10-28T20:00:33.707Z
Learning: In TypeScript test files (e.g., `test-deploy-single-request-proxy.ts`), it's acceptable to use `string` types for Ethereum addresses in interfaces (like `FeeProxyAddresses`), as stricter type safety is not necessary.

Applied to files:

  • packages/types/src/currency-types.ts
  • packages/currency/src/currencyManager.ts
  • packages/request-client.js/test/index.test.ts
📚 Learning: 2024-11-05T16:57:30.406Z
Learnt from: MantisClone
PR: RequestNetwork/requestNetwork#1481
File: packages/payment-processor/overrides/jest/index.d.ts:0-0
Timestamp: 2024-11-05T16:57:30.406Z
Learning: The `index.d.ts` file at `packages/payment-processor/overrides/jest/index.d.ts` is copied from `node_modules/types/jest` and should not be modified manually.

Applied to files:

  • packages/types/src/currency-types.ts
  • packages/currency/src/chains/declarative/index.ts
📚 Learning: 2024-11-05T16:56:32.207Z
Learnt from: MantisClone
PR: RequestNetwork/requestNetwork#1481
File: packages/payment-processor/overrides/jest/index.d.ts:0-0
Timestamp: 2024-11-05T16:56:32.207Z
Learning: The `index.d.ts` file in `packages/payment-processor/overrides/jest/` is copied from `node_modules/types/jest` and should not be edited.

Applied to files:

  • packages/types/src/currency-types.ts
  • packages/currency/src/chains/declarative/index.ts
📚 Learning: 2024-11-05T16:57:17.157Z
Learnt from: MantisClone
PR: RequestNetwork/requestNetwork#1481
File: packages/payment-processor/overrides/jest/index.d.ts:0-0
Timestamp: 2024-11-05T16:57:17.157Z
Learning: The `index.d.ts` file in `packages/payment-processor/overrides/jest` is copied from `node_modules/types/jest` and should not be edited directly.

Applied to files:

  • packages/currency/src/chains/declarative/index.ts
📚 Learning: 2024-11-06T14:48:18.698Z
Learnt from: MantisClone
PR: RequestNetwork/requestNetwork#1484
File: packages/advanced-logic/test/extensions/payment-network/any-to-near.test.ts:0-0
Timestamp: 2024-11-06T14:48:18.698Z
Learning: In `packages/advanced-logic/test/extensions/payment-network/any-to-near.test.ts`, when the existing happy path tests are deemed sufficient, additional test cases may not be necessary.

Applied to files:

  • packages/currency/src/chains/declarative/index.ts
  • packages/currency/src/currencyManager.ts
  • packages/request-client.js/test/index.test.ts
📚 Learning: 2024-11-20T18:59:38.738Z
Learnt from: rodrigopavezi
PR: RequestNetwork/requestNetwork#1475
File: packages/request-client.js/src/http-data-access.ts:214-216
Timestamp: 2024-11-20T18:59:38.738Z
Learning: When validating Ethereum addresses in TypeScript code, prefer using `ethers.utils.isAddress` function from the `ethers` library instead of regex patterns.

Applied to files:

  • packages/currency/src/currencyManager.ts
📚 Learning: 2024-10-03T07:28:57.993Z
Learnt from: kevindavee
PR: RequestNetwork/requestNetwork#1465
File: packages/currency/test/currencyManager.test.ts:156-161
Timestamp: 2024-10-03T07:28:57.993Z
Learning: The `CurrencyManager` now uses a `Map` to store currencies by ID, so testing caching behavior in `fromId` is not necessary.

Applied to files:

  • packages/currency/src/currencyManager.ts
📚 Learning: 2024-12-09T18:59:04.613Z
Learnt from: MantisClone
PR: RequestNetwork/requestNetwork#1482
File: packages/payment-processor/src/payment/erc-20-private-payment-hinkal.ts:80-99
Timestamp: 2024-12-09T18:59:04.613Z
Learning: In the `RequestNetwork` codebase, payment processor functions such as `payErc20ProxyRequestFromHinkalShieldedAddress` in `packages/payment-processor/src/payment/erc-20-private-payment-hinkal.ts` should not include explicit request validation or try/catch blocks, and should rely on the underlying components (like `hinkalObject`) to handle error reporting.

Applied to files:

  • packages/currency/src/currencyManager.ts
  • packages/request-client.js/test/index.test.ts
📚 Learning: 2025-01-20T12:49:28.095Z
Learnt from: rodrigopavezi
PR: RequestNetwork/requestNetwork#1547
File: packages/types/src/request-logic-types.ts:101-101
Timestamp: 2025-01-20T12:49:28.095Z
Learning: In the RequestNetwork codebase, the `IReturnMeta` interface in request-logic-types.ts intentionally uses `any` type for its properties (transactionManagerMeta, ignoredTransactions, pagination) to allow for flexibility in different implementations.

Applied to files:

  • packages/currency/src/currencyManager.ts
  • packages/request-client.js/test/index.test.ts
📚 Learning: 2024-10-28T15:52:05.032Z
Learnt from: MantisClone
PR: RequestNetwork/requestNetwork#1474
File: packages/payment-processor/src/payment/single-request-proxy.ts:156-160
Timestamp: 2024-10-28T15:52:05.032Z
Learning: In the `payRequestWithSingleRequestProxy` function of `single-request-proxy.ts`, failing to retrieve `tokenAddress()` is expected for `EthereumSingleRequestProxy` contracts and is not an error.

Applied to files:

  • packages/currency/src/currencyManager.ts
📚 Learning: 2024-11-08T18:24:06.144Z
Learnt from: MantisClone
PR: RequestNetwork/requestNetwork#1487
File: packages/payment-processor/test/payment/single-request-proxy.test.ts:237-246
Timestamp: 2024-11-08T18:24:06.144Z
Learning: In `packages/payment-processor/test/payment/single-request-proxy.test.ts`, when asserting the `feeProxyUsed` in emitted events from `SingleRequestProxyFactory`, retrieve the `erc20FeeProxy` (or `ethereumFeeProxy`) public variable from the `SingleRequestProxyFactory` contract instead of using `wallet.address`.

Applied to files:

  • packages/currency/src/currencyManager.ts
  • packages/request-client.js/test/index.test.ts
📚 Learning: 2024-11-04T14:32:19.189Z
Learnt from: giorgi-kiknavelidze
PR: RequestNetwork/requestNetwork#1482
File: packages/usage-examples/src/hinkal/testPayErc20FeeProxyRequestHinkal.ts:14-18
Timestamp: 2024-11-04T14:32:19.189Z
Learning: RPC URL validation is not required in the TypeScript file `packages/usage-examples/src/hinkal/testPayErc20FeeProxyRequestHinkal.ts` in the `usage-examples` package, as per the user's guidance.

Applied to files:

  • packages/currency/src/currencyManager.ts
📚 Learning: 2024-11-20T18:59:39.982Z
Learnt from: rodrigopavezi
PR: RequestNetwork/requestNetwork#1475
File: packages/request-client.js/src/http-data-access.ts:214-216
Timestamp: 2024-11-20T18:59:39.982Z
Learning: For validating Ethereum addresses, use `ethers.utils.isAddress` instead of custom regex patterns.

Applied to files:

  • packages/currency/src/currencyManager.ts
📚 Learning: 2024-10-17T18:30:55.410Z
Learnt from: MantisClone
PR: RequestNetwork/requestNetwork#1453
File: packages/smart-contracts/test/contracts/ERC20SingleRequestProxy.test.ts:150-152
Timestamp: 2024-10-17T18:30:55.410Z
Learning: In `packages/smart-contracts/test/contracts/ERC20SingleRequestProxy.test.ts`, the skipped test `'should process a partial payment correctly'` exists intentionally to show that partial payments are supported without duplicating previous happy-path tests.

Applied to files:

  • packages/request-client.js/test/index.test.ts
📚 Learning: 2024-10-28T16:03:33.215Z
Learnt from: MantisClone
PR: RequestNetwork/requestNetwork#1474
File: packages/payment-processor/test/payment/single-request-proxy.test.ts:251-270
Timestamp: 2024-10-28T16:03:33.215Z
Learning: When testing the payment-processor module, specifically in `packages/payment-processor/test/payment/single-request-proxy.test.ts`, it's acceptable to omit tests for partial payments if they have already been covered at the smart-contract level.

Applied to files:

  • packages/request-client.js/test/index.test.ts
📚 Learning: 2024-11-12T17:48:47.072Z
Learnt from: aimensahnoun
PR: RequestNetwork/requestNetwork#1488
File: packages/payment-processor/src/payment/single-request-forwarder.ts:211-219
Timestamp: 2024-11-12T17:48:47.072Z
Learning: In `packages/payment-processor/src/payment/single-request-forwarder.ts`, the error handling logic in `payWithEthereumSingleRequestForwarder` is correct and does not require changes to differentiate between ERC20 and Ethereum SingleRequestForwarder contracts.

Applied to files:

  • packages/request-client.js/test/index.test.ts
📚 Learning: 2024-12-04T05:05:19.610Z
Learnt from: MantisClone
PR: RequestNetwork/requestNetwork#1482
File: packages/payment-processor/test/payment/erc-20-private-payment-hinkal.test.ts:0-0
Timestamp: 2024-12-04T05:05:19.610Z
Learning: The function `createRequestForHinkal` in `erc-20-private-payment-hinkal.test.ts` is intended for testing purposes only and should remain in the test directory.

Applied to files:

  • packages/request-client.js/test/index.test.ts
📚 Learning: 2024-10-29T08:02:02.600Z
Learnt from: aimensahnoun
PR: RequestNetwork/requestNetwork#1474
File: packages/payment-processor/test/payment/single-request-proxy.test.ts:138-139
Timestamp: 2024-10-29T08:02:02.600Z
Learning: When testing invalid requests in `packages/payment-processor/test/payment/single-request-proxy.test.ts`, it's acceptable to use `ts-expect-error` to suppress TypeScript errors when the request intentionally lacks required properties.

Applied to files:

  • packages/request-client.js/test/index.test.ts
📚 Learning: 2024-10-28T20:00:25.780Z
Learnt from: MantisClone
PR: RequestNetwork/requestNetwork#1474
File: packages/smart-contracts/scripts/test-deploy-single-request-proxy.ts:14-32
Timestamp: 2024-10-28T20:00:25.780Z
Learning: In test files, such as `packages/smart-contracts/scripts/test-deploy-single-request-proxy.ts`, extensive error handling and input validation are considered unnecessary.

Applied to files:

  • packages/request-client.js/test/index.test.ts
📚 Learning: 2024-07-17T13:50:20.447Z
Learnt from: MantisClone
PR: RequestNetwork/requestNetwork#1386
File: packages/request-client.js/src/api/request-network.ts:74-145
Timestamp: 2024-07-17T13:50:20.447Z
Learning: The transaction manager in the Request Network SDK formats the data ensuring its integrity before it reaches methods like `preparePaymentRequest`.

Applied to files:

  • packages/request-client.js/test/index.test.ts
📚 Learning: 2024-11-21T08:34:21.320Z
Learnt from: rodrigopavezi
PR: RequestNetwork/requestNetwork#1475
File: packages/types/src/cipher-provider-types.ts:4-11
Timestamp: 2024-11-21T08:34:21.320Z
Learning: In the `ICipherProvider` interface in `packages/types/src/cipher-provider-types.ts`, the team prefers to keep methods generic by using `any` types to allow maximum flexibility.

Applied to files:

  • packages/request-client.js/test/index.test.ts
📚 Learning: 2024-11-08T20:01:10.313Z
Learnt from: MantisClone
PR: RequestNetwork/requestNetwork#1487
File: packages/payment-processor/src/payment/single-request-proxy.ts:0-0
Timestamp: 2024-11-08T20:01:10.313Z
Learning: In `packages/payment-processor/src/payment/single-request-proxy.ts`, the team prefers not to store or validate decoded values that are not needed.

Applied to files:

  • packages/request-client.js/test/index.test.ts
📚 Learning: 2024-11-21T09:02:26.971Z
Learnt from: rodrigopavezi
PR: RequestNetwork/requestNetwork#1475
File: packages/transaction-manager/test/unit/utils/test-data.ts:92-104
Timestamp: 2024-11-21T09:02:26.971Z
Learning: In `packages/transaction-manager/test/unit/utils/test-data.ts`, the `fakeEpkCipherProvider`'s `decrypt` method accepts an `options` object (e.g., `options: { identity }`) instead of directly passing `identity`. This design allows the cipher interface to be more generic and accommodate additional options for different providers' encryption and decryption methods as needed.

Applied to files:

  • packages/request-client.js/test/index.test.ts
📚 Learning: 2024-11-08T20:01:10.313Z
Learnt from: MantisClone
PR: RequestNetwork/requestNetwork#1487
File: packages/payment-processor/src/payment/single-request-proxy.ts:0-0
Timestamp: 2024-11-08T20:01:10.313Z
Learning: In `packages/payment-processor/src/payment/single-request-proxy.ts`, when decoding event data, the team prefers not to include documentation of the event data structure if maintaining it would be difficult.

Applied to files:

  • packages/request-client.js/test/index.test.ts
🧬 Code Graph Analysis (3)
packages/currency/src/chains/declarative/data/ton.ts (2)
packages/currency/src/chains/declarative/data/starknet.ts (1)
  • chainId (1-1)
packages/currency/src/chains/declarative/data/aleo.ts (1)
  • chainId (1-1)
packages/currency/src/chains/declarative/data/starknet.ts (2)
packages/currency/src/chains/declarative/data/aleo.ts (1)
  • chainId (1-1)
packages/currency/src/chains/declarative/data/ton.ts (1)
  • chainId (1-1)
packages/currency/src/chains/declarative/data/aleo.ts (2)
packages/currency/src/chains/declarative/data/starknet.ts (1)
  • chainId (1-1)
packages/currency/src/chains/declarative/data/ton.ts (1)
  • chainId (1-1)
⏰ 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: build-and-test
🔇 Additional comments (7)
packages/types/src/currency-types.ts (1)

45-45: Type union extension LGTM.

The added declarative chains align with new validations and chain data.

packages/currency/src/chains/declarative/index.ts (1)

5-7: All declarative chains wired correctly

I’ve confirmed that:

  • DeclarativeChainName (in packages/types/src/currency-types.ts) includes 'ton' | 'starknet' | 'aleo'.
  • The files packages/currency/src/chains/declarative/data/ton.ts, starknet.ts, and aleo.ts all exist and export the correct chainId.

LGTM.

packages/request-client.js/test/index.test.ts (1)

8-8: Importing CurrencyTypes is appropriate here.

Used for typing DeclarativeChainName in the new param tests.

packages/currency/src/currencyManager.ts (4)

270-276: Address validation branching extended correctly for TON/Starknet/Aleo.

Near, Tron, Solana paths preserved; unknown networks still fall back to EVM validation.

Consider adding unit tests in packages/currency/test for valid/invalid addresses per new network to catch regressions early.


302-314: TON address validator looks good.

Address.parse throws on invalid input; boolean return is correct.


315-327: Starknet address validator is appropriate.

validateAndParseAddress normalizes or throws; boolean return is correct.


3-5: Dependencies and imports verified in packages/currency

  • package.json declares
    • @ton/core ^0.61.0
    • starknet ^7.6.4
    • @provablehq/sdk ^0.9.5
  • currencyManager.ts
    • Imports at lines 3–5
    • Validator calls at lines 271–275
    • Implementations at lines 307 (validateTonAddress), 320 (validateStarknetAddress), 333 (validateAleoAddress)

All three modules are present and the imported symbols match their documented APIs (Address.parse, validateAndParseAddress, Address.from_string). No changes required.

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

🧹 Nitpick comments (2)
packages/currency/src/currencyManager.ts (2)

301-312: TON validation: minor hardening (trim and rely on parse throwing)

Trim input and rely on the parse side-effect to determine validity. No behavior change otherwise.

-  validateTonAddress(address: string): boolean {
-    try {
-      return !!Address.parse(address);
-    } catch {
-      return false;
-    }
-  }
+  validateTonAddress(address: string): boolean {
+    try {
+      const input = address?.trim();
+      if (!input) return false;
+      Address.parse(input); // throws on invalid
+      return true;
+    } catch {
+      return false;
+    }
+  }

314-325: Starknet validation: minor hardening (trim before validate)

Trim the address before parsing to avoid whitespace-related false negatives.

-  validateStarknetAddress(address: string): boolean {
-    try {
-      return !!validateAndParseAddress(address);
-    } catch {
-      return false;
-    }
-  }
+  validateStarknetAddress(address: string): boolean {
+    try {
+      const input = address?.trim();
+      if (!input) return false;
+      validateAndParseAddress(input); // throws on invalid, returns normalized address on success
+      return true;
+    } catch {
+      return false;
+    }
+  }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between c3583f7 and 56e7ee2.

⛔ Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (2)
  • packages/currency/package.json (1 hunks)
  • packages/currency/src/currencyManager.ts (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/currency/package.json
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2024-11-20T18:59:38.738Z
Learnt from: rodrigopavezi
PR: RequestNetwork/requestNetwork#1475
File: packages/request-client.js/src/http-data-access.ts:214-216
Timestamp: 2024-11-20T18:59:38.738Z
Learning: When validating Ethereum addresses in TypeScript code, prefer using `ethers.utils.isAddress` function from the `ethers` library instead of regex patterns.

Applied to files:

  • packages/currency/src/currencyManager.ts
⏰ 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: build-and-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: 4

♻️ Duplicate comments (2)
packages/currency/src/currencyManager.ts (2)

3-6: ESM-first imports may break CJS builds; align package/module strategy or lazy-load heavy deps

@ton/core and starknet are ESM-first. Importing them at top level from a package published as CJS risks runtime failures and increases bundle size. Please apply one of the previously recommended options (set package to ESM, emit CJS, or ensure bundler interop); optionally consider dynamic import() inside validators to defer cost.


270-276: Normalize network and trim address before routing to validators

Avoid false negatives due to casing/whitespace by normalizing once and reusing. This also ensures the ETH fallback validates a trimmed address.

       case RequestLogicTypes.CURRENCY.ETH:
       case RequestLogicTypes.CURRENCY.ERC20:
       case RequestLogicTypes.CURRENCY.ERC777:
-        if (NearChains.isChainSupported(currency.network)) {
-          return isValidNearAddress(address, currency.network);
-        } else if (currency.network === 'tron' || currency.network === 'solana') {
-          return addressValidator.validate(address, currency.network);
-        } else if (currency.network === 'ton') {
-          return this.validateTonAddress(address);
-        } else if (currency.network === 'starknet') {
-          return this.validateStarknetAddress(address);
-        } else if (currency.network === 'aleo') {
-          return this.validateAleoAddress(address);
+        if (NearChains.isChainSupported(network)) {
+          return isValidNearAddress(normalizedAddress, network);
+        } else if (network === 'tron' || network === 'solana') {
+          return addressValidator.validate(normalizedAddress, network);
+        } else if (network === 'ton') {
+          return this.validateTonAddress(normalizedAddress);
+        } else if (network === 'starknet') {
+          return this.validateStarknetAddress(normalizedAddress);
+        } else if (network === 'aleo') {
+          return this.validateAleoAddress(normalizedAddress);
         }
-        return addressValidator.validate(address, 'ETH');
+        return addressValidator.validate(normalizedAddress, 'ETH');

Add near the start of this branch:

// normalize once
const network = (currency as any).network?.toString().toLowerCase();
const normalizedAddress = typeof address === 'string' ? address.trim() : '';
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 56e7ee2 and 679e775.

📒 Files selected for processing (3)
  • packages/currency/package.json (1 hunks)
  • packages/currency/src/currencyManager.ts (3 hunks)
  • packages/currency/test/currencyManager.test.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/currency/package.json
🧰 Additional context used
🧠 Learnings (4)
📚 Learning: 2024-11-20T18:59:38.738Z
Learnt from: rodrigopavezi
PR: RequestNetwork/requestNetwork#1475
File: packages/request-client.js/src/http-data-access.ts:214-216
Timestamp: 2024-11-20T18:59:38.738Z
Learning: When validating Ethereum addresses in TypeScript code, prefer using `ethers.utils.isAddress` function from the `ethers` library instead of regex patterns.

Applied to files:

  • packages/currency/src/currencyManager.ts
  • packages/currency/test/currencyManager.test.ts
📚 Learning: 2024-12-09T18:59:04.613Z
Learnt from: MantisClone
PR: RequestNetwork/requestNetwork#1482
File: packages/payment-processor/src/payment/erc-20-private-payment-hinkal.ts:80-99
Timestamp: 2024-12-09T18:59:04.613Z
Learning: In the `RequestNetwork` codebase, payment processor functions such as `payErc20ProxyRequestFromHinkalShieldedAddress` in `packages/payment-processor/src/payment/erc-20-private-payment-hinkal.ts` should not include explicit request validation or try/catch blocks, and should rely on the underlying components (like `hinkalObject`) to handle error reporting.

Applied to files:

  • packages/currency/src/currencyManager.ts
📚 Learning: 2024-11-06T14:48:18.698Z
Learnt from: MantisClone
PR: RequestNetwork/requestNetwork#1484
File: packages/advanced-logic/test/extensions/payment-network/any-to-near.test.ts:0-0
Timestamp: 2024-11-06T14:48:18.698Z
Learning: In `packages/advanced-logic/test/extensions/payment-network/any-to-near.test.ts`, when the existing happy path tests are deemed sufficient, additional test cases may not be necessary.

Applied to files:

  • packages/currency/test/currencyManager.test.ts
📚 Learning: 2024-11-21T09:06:12.938Z
Learnt from: rodrigopavezi
PR: RequestNetwork/requestNetwork#1475
File: packages/transaction-manager/test/unit/utils/test-data.ts:87-119
Timestamp: 2024-11-21T09:06:12.938Z
Learning: In `packages/transaction-manager/test/unit/utils/test-data.ts`, mocks like `fakeEpkCipherProvider` do not require extensive test coverage for input validation and error handling.

Applied to files:

  • packages/currency/test/currencyManager.test.ts
🧬 Code Graph Analysis (1)
packages/currency/test/currencyManager.test.ts (1)
packages/payment-processor/test/payment/shared.ts (1)
  • currencyManager (4-21)
⏰ 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: build-and-test
🔇 Additional comments (1)
packages/currency/test/currencyManager.test.ts (1)

769-775: LGTM: solid positive cases for Aleo (lower/upper/trim)

These tests validate canonical, uppercase, and padded inputs against Bech32 decoding. Good coverage for happy path.

@PaulvanMotman PaulvanMotman requested review from alexandre-abrioux and kevindavee and removed request for yomarion August 11, 2025 13:41
@PaulvanMotman PaulvanMotman merged commit a5ee3af into master Aug 13, 2025
10 checks passed
@PaulvanMotman PaulvanMotman deleted the fix/ton_address_validation branch August 13, 2025 08:31
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.

5 participants