Skip to content

Commit c681aca

Browse files
committed
scripts
1 parent 0ed548a commit c681aca

File tree

2 files changed

+24
-10
lines changed

2 files changed

+24
-10
lines changed

src/data/fetchPools.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ const run = async () => {
5252
asset_b_symbol: symbolMap[pool.asset_b],
5353
share_asset_symbol: symbolMap[pool.share_asset],
5454
share_asset_id: pool.share_asset,
55-
balance_a: parseInt(pool.balance_a),
56-
balance_b: parseInt(pool.balance_b),
55+
balance_a: pool.balance_a,
56+
balance_b: pool.balance_b,
5757
taker_fee_percent: pool.taker_fee_percent,
5858
withdrawal_fee_percent: pool.withdrawal_fee_percent,
5959
};
@@ -77,8 +77,8 @@ const run = async () => {
7777
bs: symbolMap[pool.asset_b],
7878
sa: symbolMap[pool.share_asset],
7979
said: pool.share_asset,
80-
ba: parseInt(pool.balance_a),
81-
bb: parseInt(pool.balance_b),
80+
ba: pool.balance_a,
81+
bb: pool.balance_b,
8282
tfp: pool.taker_fee_percent,
8383
};
8484
});

src/nanoeffects/LiquidityPools.ts

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)