Skip to content

Commit 29f8b04

Browse files
committed
getStrategiesByPairs supports all pairs
1 parent 44a2e1c commit 29f8b04

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "@bancor/carbon-sdk",
33
"type": "module",
44
"source": "src/index.ts",
5-
"version": "0.0.122-DEV",
5+
"version": "0.0.123-DEV",
66
"description": "The SDK is a READ-ONLY tool, intended to facilitate working with Carbon contracts. It's a convenient wrapper around our matching algorithm, allowing programs and users get a ready to use transaction data that will allow them to manage strategies and fulfill trades",
77
"main": "dist/index.cjs",
88
"module": "dist/index.js",

src/strategy-management/Toolkit.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -347,21 +347,28 @@ export class Toolkit {
347347
* If the cache is synced, it will return the strategies from the cache.
348348
* Otherwise, it will fetch the strategies from the chain.
349349
*
350-
* @param {TokenPair[]} pairs - List of pairs to get strategies for.
350+
* @param {TokenPair[]} pairs - List of pairs to get strategies for. If undefined, all pairs will be fetched.
351351
*
352352
* @returns {Promise<{
353353
* pair: TokenPair;
354354
* strategies: Strategy[];
355355
* }[]>} An array of pairs and their strategies.
356356
*/
357-
public async getStrategiesByPairs(pairs: TokenPair[]): Promise<
357+
public async getStrategiesByPairs(pairs?: TokenPair[]): Promise<
358358
{
359359
pair: TokenPair;
360360
strategies: Strategy[];
361361
}[]
362362
> {
363363
logger.debug('getStrategiesByPairs called', arguments);
364364

365+
let pairsToFetch = pairs;
366+
if (!pairsToFetch) {
367+
pairsToFetch = this._cache
368+
? this._cache.getCachedPairs()
369+
: await this._api.reader.pairs();
370+
}
371+
365372
let encodedStrategies:
366373
| {
367374
pair: TokenPair;
@@ -370,14 +377,16 @@ export class Toolkit {
370377
| undefined;
371378

372379
if (this._cache) {
373-
encodedStrategies = await this._cache.getStrategiesByPairs(pairs);
380+
encodedStrategies = await this._cache.getStrategiesByPairs(pairsToFetch);
374381
}
375382

376383
if (encodedStrategies) {
377384
logger.debug('getStrategiesByPairs fetched from cache');
378385
} else {
379386
logger.debug('getStrategiesByPairs fetching from chain');
380-
encodedStrategies = await this._api.reader.strategiesByPairs(pairs);
387+
encodedStrategies = await this._api.reader.strategiesByPairs(
388+
pairsToFetch
389+
);
381390
}
382391

383392
const decodedStrategies: {
@@ -407,6 +416,7 @@ export class Toolkit {
407416

408417
logger.debug('getStrategiesByPairs info:', {
409418
pairs,
419+
pairsToFetch,
410420
encodedStrategies,
411421
decodedStrategies,
412422
strategies,

0 commit comments

Comments
 (0)