Skip to content

feat(sdk): add getMessagesInRange for block/slot-based CCIP message d…#220

Draft
aelmanaa wants to merge 1 commit intomainfrom
feat/sdk-get-messages-in-range
Draft

feat(sdk): add getMessagesInRange for block/slot-based CCIP message d…#220
aelmanaa wants to merge 1 commit intomainfrom
feat/sdk-get-messages-in-range

Conversation

@aelmanaa
Copy link
Copy Markdown
Collaborator

@aelmanaa aelmanaa commented Apr 7, 2026

This pull request introduces a new feature for range-based discovery of CCIP messages in the SDK, along with related updates to the CLI and tests. The main addition is the getMessagesInRange() method, which enables efficient scanning and decoding of CCIP messages across block/slot ranges. The implementation includes robust test coverage and code refactoring to share lane resolution logic. Additionally, two new Creditcoin networks are added to the chain selectors.

CCIP Message Discovery Enhancements

  • Added the getMessagesInRange() method to the abstract Chain class and exported it from the SDK, enabling range-based CCIP message discovery using getLogs and decodeMessage. This returns an AsyncIterableIterator<CCIPRequest> and is documented for both EVM and Solana chains. (ccip-sdk/src/chain.ts, ccip-sdk/src/requests.ts, ccip-sdk/src/index.ts, CHANGELOG.md) [1] [2] [3] [4]
  • Introduced a shared resolveLane helper to unify lane resolution logic for decoded messages, reducing code duplication in message discovery functions. (ccip-sdk/src/requests.ts) [1] [2] [3]

Testing Improvements

  • Added comprehensive tests for getMessagesInRange, covering correct message extraction, lane resolution for different CCIP versions, log filtering, transaction fallback, and empty results. (ccip-sdk/src/requests.test.ts)

Chain Selector Updates

  • Added Creditcoin mainnet and testnet to the chain selectors. (ccip-sdk/src/selectors.ts)

Minor/Other Changes

  • Updated SDK and CLI version strings to reflect the new build. (ccip-sdk/src/api/index.ts, ccip-cli/src/index.ts) [1] [2]
  • Minor code style and import adjustments for maintainability. (ccip-sdk/src/evm/errors.ts, ccip-sdk/src/requests.ts) [1] [2] [3]

These changes collectively improve the SDK's ability to discover and process CCIP messages across block ranges, making it easier to build tools that require historical or batch message analysis.

@aelmanaa aelmanaa requested review from a team and PabloMansanet as code owners April 7, 2026 22:22
@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 7, 2026

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

Project Deployment Actions Updated (UTC)
ccip-tools-ts Ready Ready Preview, Comment Apr 7, 2026 11:12pm

Request Review

@aelmanaa aelmanaa marked this pull request as draft April 7, 2026 22:22
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 7, 2026

Coverage Report

ℹ tests 779
ℹ suites 228
ℹ pass 777
ℹ fail 0
ℹ cancelled 0
ℹ skipped 2
ℹ todo 0
ℹ duration_ms 99238.843454

> @chainlink/ccip-cli@1.4.2 test
> node --test

▶ lane-latency command
  ✔ should output JSON format correctly (5.562522ms)
  ✔ should resolve chain IDs to chain selectors (0.771841ms)
  ✔ should use custom API URL when provided (0.73549ms)
  ✔ should output log format correctly (0.755964ms)
  ✔ should handle chain IDs as input (0.616683ms)
  ✔ should handle chain selectors as input (2.867685ms)
  ✔ should throw CCIPApiClientNotAvailableError when --no-api flag is set (1.254483ms)
  ✔ should work normally when --no-api flag is false (0.730323ms)
  ✔ should forward blockConfirmations to API URL (0.742589ms)
  ✔ should not include numOfBlocks when blockConfirmations is not provided (0.909528ms)
  ▶ CCIP_API environment variable integration
    ✔ should respect CCIP_API=false environment variable (0.79814ms)
  ✔ CCIP_API environment variable integration (1.706672ms)
✔ lane-latency command (18.729346ms)
▶ search messages command
  ✔ should throw CCIPApiClientNotAvailableError when --no-api flag is set (2.433286ms)
  ✔ should output JSON format correctly (12.041638ms)
  ✔ should pass sender filter to API (5.036798ms)
  ✔ should pass receiver filter to API (5.400525ms)
  ✔ should resolve source chain to selector (4.258249ms)
  ✔ should resolve dest chain to selector (3.41286ms)
  ✔ should pass manual-exec-only filter to API (4.372201ms)
  ✔ should treat limit 0 as unlimited (5.143094ms)
  ✔ should respect limit parameter (8.678955ms)
  ✔ should warn when no results found (2.608239ms)
  ✔ should use custom API URL when provided (2.548755ms)
  ✔ should warn on negative limit and fall back to default (2.055449ms)
  ✔ should output log format (1.573019ms)
✔ search messages command (61.803093ms)
▶ e2e command show EVM
  ▶ pretty format (default)
    ✔ should show complete CCIP transaction details EVM to EVM (12869.556575ms)
  ✔ pretty format (default) (12870.57206ms)
  ▶ json format
    ✔ should output valid JSON with all expected fields (9770.432037ms)
  ✔ json format (9770.676064ms)
  ▶ log format
    ✔ should output in log format with object assignments (10022.590899ms)
  ✔ log format (10022.805061ms)
  ▶ verbose flag
    ✔ should work with verbose flag enabled (11053.506161ms)
  ✔ verbose flag (11053.734953ms)
  ▶ error handling
    ✔ should handle invalid transaction hash gracefully (5622.45438ms)
    ✔ should require transaction hash argument (1484.124799ms)
  ✔ error handling (7106.842348ms)
  ✔ should show complete CCIP transaction details EVM to Aptos (7869.076045ms)
  ✔ should show complete CCIP transaction details EVM to Solana (6522.350957ms)
✔ e2e command show EVM (65217.280885ms)
▶ e2e command show Solana
  ✔ should show complete CCIP transaction details Solana to EVM (8976.973201ms)
✔ e2e command show Solana (8977.196365ms)
▶ e2e command show Aptos
  ✔ should show complete CCIP transaction details Aptos to EVM (7883.215024ms)
✔ e2e command show Aptos (7883.406495ms)
﹣ e2e command show TON (0.049599ms) # SKIP
▶ formatCCIPError
  ✔ should return null for non-CCIPError instances (0.969082ms)
  ✔ should format CCIPError with code and message (0.406406ms)
  ✔ should include help section with recovery hint (0.129671ms)
  ✔ should include note section for transient errors (0.218425ms)
  ✔ should include retry timing for transient errors with retryAfterMs (0.251357ms)
  ✔ should not include note section for permanent errors (0.185376ms)
  ✔ should format error with structured output (0.16994ms)
  ✔ should include stack trace when verbose is true (0.275459ms)
  ✔ should not include stack trace when verbose is false (0.170541ms)
✔ formatCCIPError (4.059498ms)
ℹ tests 43
ℹ suites 13
ℹ pass 43
ℹ fail 0
ℹ cancelled 0
ℹ skipped 0
ℹ todo 0
ℹ duration_ms 82287.272448
-------------------------------|---------|----------|---------|---------|---------------------------
File                           | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s         
-------------------------------|---------|----------|---------|---------|---------------------------
All files                      |   74.97 |    76.76 |   60.58 |   74.97 |                           
 ccip-cli/src                  |   83.78 |    77.77 |      50 |   83.78 |                           
  index.ts                     |   83.78 |    77.77 |      50 |   83.78 | ...64,87-91,97-98,103-108 
 ccip-cli/src/commands         |   52.42 |    71.55 |   51.85 |   52.42 |                           
  index.ts                     |     100 |      100 |     100 |     100 |                           
  lane-latency.ts              |   72.56 |     90.9 |   33.33 |   72.56 | 41-56,63-70,105-111       
  manual-exec.ts               |   26.33 |      100 |       0 |   26.33 | 61-114,121-131,133-260    
  parse.ts                     |   57.14 |      100 |       0 |   57.14 | 46-50,57-64,66-91         
  search.ts                    |   81.25 |      100 |       0 |   81.25 | 24-29                     
  send.ts                      |   16.66 |      100 |       0 |   16.66 | ...72-179,189-218,220-414 
  show.ts                      |   84.69 |    59.32 |      60 |   84.69 | ...90-191,204-217,248-249 
  supported-tokens.ts          |   19.47 |      100 |       0 |   19.47 | ...11-231,233-288,290-303 
  token.ts                     |   22.72 |      100 |       0 |   22.72 | 24-53,60-67,69-132        
  types.ts                     |     100 |      100 |     100 |     100 |                           
  utils.ts                     |   85.31 |    73.57 |    92.3 |   85.31 | ...86-596,604-612,622-628 
 ccip-cli/src/commands/search  |   49.39 |    85.29 |   14.28 |   49.39 |                           
  messages.ts                  |   49.39 |    85.29 |   14.28 |   49.39 | ...86-188,190-212,214-249 
 ccip-cli/src/providers        |    51.9 |    75.51 |      16 |    51.9 |                           
  aptos.ts                     |   53.65 |      100 |       0 |   53.65 | ...70,78-85,91-92,101-123 
  evm.ts                       |    39.7 |      100 |       0 |    39.7 | 23,40-50,56-85,97-136     
  index.ts                     |   81.65 |    72.72 |      80 |   81.65 | 50-51,190-229             
  solana.ts                    |   50.42 |      100 |       0 |   50.42 | ...-71,79-85,89-90,99-117 
  sui.ts                       |   64.28 |      100 |       0 |   64.28 | 10-14                     
  ton.ts                       |   14.58 |      100 |       0 |   14.58 | 22-144                    
 ccip-sdk/src                  |   94.44 |    82.23 |   91.46 |   94.44 |                           
  chain.ts                     |   93.18 |    81.33 |   68.18 |   93.18 | ...55,1704-1705,1738-1739 
  commits.ts                   |     100 |    95.23 |     100 |     100 | 52                        
  execution.ts                 |   92.19 |     92.3 |     100 |   92.19 | 130-137,149-156           
  explorer.ts                  |     100 |      100 |     100 |     100 |                           
  extra-args.ts                |     100 |    86.66 |     100 |     100 | 179,214                   
  gas.ts                       |   89.75 |       40 |     100 |   89.75 | 108-119,147-151           
  http-status.ts               |     100 |      100 |     100 |     100 |                           
  index.ts                     |     100 |      100 |     100 |     100 |                           
  messages.ts                  |   88.48 |    45.09 |     100 |   88.48 | ...19-220,229-230,254-255 
  offchain.ts                  |   91.94 |    76.74 |     100 |   91.94 | ...90,208,223-225,227-233 
  requests.ts                  |    92.1 |    83.33 |     100 |    92.1 | ...90,222,345-358,360-364 
  supported-chains.ts          |     100 |      100 |     100 |     100 |                           
  types.ts                     |     100 |      100 |     100 |     100 |                           
  utils.ts                     |    96.3 |    90.12 |     100 |    96.3 | ...52,768,869-870,877-885 
 ccip-sdk/src/api              |   93.75 |       85 |   94.11 |   93.75 |                           
  index.ts                     |   93.75 |       85 |   94.11 |   93.75 | ...39-744,755-758,761-764 
 ccip-sdk/src/aptos            |    55.7 |    69.23 |   55.73 |    55.7 |                           
  exec.ts                      |   29.31 |      100 |       0 |   29.31 | 18-58                     
  hasher.ts                    |   76.31 |       80 |   66.66 |   76.31 | 19-38,52-58               
  index.ts                     |    56.4 |    74.64 |   58.13 |    56.4 | ...26-828,832-858,862-873 
  logs.ts                      |   78.52 |    57.44 |      75 |   78.52 | ...90-196,200-233,264-268 
  send.ts                      |    25.2 |      100 |       0 |    25.2 | 10-51,62-79,92-123        
  token.ts                     |   23.75 |       75 |     100 |   23.75 | 35-156                    
  types.ts                     |   65.62 |      100 |       0 |   65.62 | 25-32,64-88               
 ccip-sdk/src/errors           |   87.33 |    75.94 |   47.96 |   87.33 |                           
  CCIPError.ts                 |     100 |      100 |     100 |     100 |                           
  codes.ts                     |     100 |      100 |     100 |     100 |                           
  index.ts                     |     100 |      100 |     100 |     100 |                           
  recovery.ts                  |     100 |      100 |     100 |     100 |                           
  specialized.ts               |   84.59 |    70.88 |   45.29 |   84.59 | ...12,3333-3342,3363-3372 
  utils.ts                     |   94.44 |    81.48 |     100 |   94.44 | 15,17,22,24               
 ccip-sdk/src/evm              |   83.14 |    74.31 |   88.88 |   83.14 |                           
  const.ts                     |     100 |      100 |     100 |     100 |                           
  errors.ts                    |   84.03 |    78.57 |     100 |   84.03 | ...57-164,170-172,219-237 
  extra-args.ts                |   94.44 |    61.66 |     100 |   94.44 | ...83-184,209-210,326-338 
  fork.test.data.ts            |     100 |      100 |     100 |     100 |                           
  gas.ts                       |   97.97 |    53.33 |     100 |   97.97 | 72-73,75                  
  hasher.ts                    |     100 |     92.3 |     100 |     100 | 134                       
  index.ts                     |   80.47 |       75 |      90 |   80.47 | ...71,2135-2151,2177-2184 
  logs.ts                      |   34.32 |    68.42 |      25 |   34.32 | ...13-214,229-258,275-302 
  messages.ts                  |     100 |      100 |     100 |     100 |                           
  offchain.ts                  |   81.25 |    33.33 |     100 |   81.25 | 11,13-14                  
  types.ts                     |     100 |      100 |     100 |     100 |                           
 ccip-sdk/src/evm/viem         |   77.72 |       92 |   69.23 |   77.72 |                           
  client-adapter.ts            |     100 |     92.3 |     100 |     100 | 48                        
  index.ts                     |     100 |      100 |     100 |     100 |                           
  wallet-adapter.ts            |   63.09 |     90.9 |   55.55 |   63.09 | ...6,53-73,91-124,131-157 
 ccip-sdk/src/hasher           |   94.29 |    78.94 |     100 |   94.29 |                           
  common.ts                    |     100 |      100 |     100 |     100 |                           
  hasher.ts                    |     100 |    66.66 |     100 |     100 | 19                        
  index.ts                     |     100 |      100 |     100 |     100 |                           
  merklemulti.ts               |   93.43 |       78 |     100 |   93.43 | ...59-260,306-307,315-316 
 ccip-sdk/src/shared           |   88.05 |    69.23 |     100 |   88.05 |                           
  bcs-codecs.ts                |   87.87 |    66.66 |     100 |   87.87 | 75-87,104-106             
  constants.ts                 |     100 |      100 |     100 |     100 |                           
 ccip-sdk/src/solana           |   72.61 |    67.29 |   77.01 |   72.61 |                           
  cleanup.ts                   |   26.63 |    66.66 |   33.33 |   26.63 | 43-53,59-101,113-226      
  exec.ts                      |   68.47 |    63.63 |   66.66 |   68.47 | ...66,283-290,433,450-452 
  fork.test.data.ts            |     100 |      100 |     100 |     100 |                           
  hasher.ts                    |   96.58 |    81.81 |     100 |   96.58 | 67-70                     
  index.ts                     |   76.88 |       75 |   78.84 |   76.88 | ...52,1556-1577,1581-1614 
  logs.ts                      |   74.83 |    38.88 |     100 |   74.83 | 38-39,50-51,53-54,56-88   
  offchain.ts                  |   68.88 |    33.33 |     100 |   68.88 | 30-43                     
  patchBorsh.ts                |   78.31 |       50 |     100 |   78.31 | 34-35,41-47,65-66,72-78   
  send.ts                      |    76.5 |    38.09 |      80 |    76.5 | ...71-272,277-285,327-366 
  types.ts                     |     100 |      100 |     100 |     100 |                           
  utils.ts                     |   67.41 |    68.96 |   63.63 |   67.41 | ...36-439,442-444,476-491 
 ccip-sdk/src/sui              |   32.62 |    89.47 |   17.24 |   32.62 |                           
  discovery.ts                 |   14.86 |      100 |       0 |   14.86 | 20-36,49-185,188-222      
  events.ts                    |    19.9 |      100 |       0 |    19.9 | ...18-275,280-397,406-427 
  exec.ts                      |   31.29 |      100 |       0 |   31.29 | 31-74,86-131              
  hasher.ts                    |   98.16 |    66.66 |     100 |   98.16 | 33,49                     
  index.ts                     |   40.44 |    93.18 |   17.94 |   40.44 | ...12-813,817-818,822-823 
  objects.ts                   |   18.93 |      100 |       0 |   18.93 | ...04-119,133-184,195-338 
 ccip-sdk/src/sui/manuallyExec |   39.63 |      100 |       0 |   39.63 |                           
  encoder.ts                   |   47.67 |      100 |       0 |   47.67 | 42-86                     
  index.ts                     |   34.35 |      100 |       0 |   34.35 | 46-131                    
 ccip-sdk/src/ton              |   74.68 |    82.05 |   64.78 |   74.68 |                           
  exec.ts                      |     100 |      100 |     100 |     100 |                           
  hasher.ts                    |   77.95 |    77.77 |      75 |   77.95 | 99-107,155-186            
  index.ts                     |   70.77 |    75.86 |   52.27 |   70.77 | ...08,1215-1216,1223-1224 
  logs.ts                      |     100 |    98.43 |     100 |     100 | 56                        
  send.ts                      |   96.49 |    70.83 |     100 |   96.49 | 38-45                     
  types.ts                     |   77.94 |    69.23 |   66.66 |   77.94 | ...-73,91,118-131,133-136 
  utils.ts                     |   60.88 |    83.33 |    87.5 |   60.88 | ...55-261,269-327,329-332 
-------------------------------|---------|----------|---------|---------|---------------------------

@aelmanaa aelmanaa force-pushed the feat/sdk-get-messages-in-range branch from 1af4090 to 19b6a56 Compare April 7, 2026 23:03
Comment thread ccip-sdk/src/requests.ts
): AsyncIterableIterator<CCIPRequest> {
for await (const log of source.getLogs({
...opts,
topics: opts.topics ?? ['CCIPSendRequested', 'CCIPMessageSent'],
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Improvement: CCIPSendRequested is for CCIP<=1.5, which is EVM-only;
CCIP v1.6 and v2.0, it's called CCIPMessageSent.
If you inspect on source.network.family to pass/default only the later on anything other than EVM, you may make this function more compatible with all chain families
Context: Aptos (and maybe Sui) can only handle 1 topic in getLogs' opts, because it needs to inspect some "array" of events on-chain which are named and can therefore only handle exactly 1 topic.

Suggested change
topics: opts.topics ?? ['CCIPSendRequested', 'CCIPMessageSent'],
topics: opts.topics ?? [...(source.network.family === ChainFamily.EVM ? ['CCIPSendRequested'] : []), 'CCIPMessageSent'],

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.

2 participants