@@ -62,13 +62,23 @@ function fetchLiquidityPools(
6262 for ( let i = 1 ; i < iterations ; i ++ ) {
6363 let nextPage ;
6464 try {
65+ // Compute a start id that is one higher than the last fetched id's numeric suffix.
66+ // The DB API treats the start id as inclusive, so passing the last id returns it again.
67+ let startId = pools [ pools . length - 1 ] . id ;
68+ try {
69+ const parts = startId . split ( "." ) ;
70+ const lastNum = parseInt ( parts [ parts . length - 1 ] , 10 ) ;
71+ if ( ! isNaN ( lastNum ) ) {
72+ parts [ parts . length - 1 ] = String ( lastNum + 1 ) ;
73+ startId = parts . join ( "." ) ;
74+ }
75+ } catch ( e ) {
76+ // if anything goes wrong, fall back to the original id (existing behavior)
77+ }
78+
6579 nextPage = await currentAPI
6680 . db_api ( )
67- . exec ( "list_liquidity_pools" , [
68- limit ,
69- pools [ pools . length - 1 ] . id ,
70- true ,
71- ] ) ;
81+ . exec ( "list_liquidity_pools" , [ limit , startId , true ] ) ;
7282 } catch ( error ) {
7383 console . log ( { error } ) ;
7484 if ( ! existingAPI ) {
@@ -79,7 +89,11 @@ function fetchLiquidityPools(
7989 }
8090
8191 if ( nextPage && nextPage . length ) {
82- pools = [ ...pools , ...nextPage ] ;
92+ const isDuplicate = nextPage [ 0 ] . id === pools [ pools . length - 1 ] . id ;
93+ const newItems = isDuplicate ? nextPage . slice ( 1 ) : nextPage ;
94+ if ( newItems . length > 0 ) {
95+ pools = [ ...pools , ...newItems ] ;
96+ }
8397 if ( nextPage . length < limit ) {
8498 break ;
8599 }
0 commit comments