@scallop-io/sui-scallop-sdk 1.3.41 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/constants/tokenBucket.d.ts +1 -1
- package/dist/index.js +194 -186
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +194 -186
- package/dist/index.mjs.map +1 -1
- package/dist/models/scallopQuery.d.ts +34 -14
- package/package.json +1 -1
- package/src/constants/tokenBucket.ts +1 -1
- package/src/models/scallopQuery.ts +38 -31
- package/src/queries/coreQuery.ts +184 -189
- package/src/queries/portfolioQuery.ts +17 -16
- package/src/queries/sCoinQuery.ts +2 -2
- package/src/queries/spoolQuery.ts +2 -2
- package/src/utils/indexer.ts +9 -3
- package/src/utils/tokenBucket.ts +2 -2
package/src/queries/coreQuery.ts
CHANGED
|
@@ -305,222 +305,217 @@ export const getMarketPool = async (
|
|
|
305
305
|
marketObject?: SuiObjectData | null,
|
|
306
306
|
coinPrice?: number
|
|
307
307
|
): Promise<MarketPool | undefined> => {
|
|
308
|
-
|
|
309
|
-
coinPrice
|
|
310
|
-
|
|
311
|
-
(await query.utils.getCoinPrices([poolCoinName]))?.[poolCoinName];
|
|
312
|
-
|
|
313
|
-
if (indexer) {
|
|
314
|
-
const marketPoolIndexer = await query.indexer.getMarketPool(poolCoinName);
|
|
315
|
-
if (!marketPoolIndexer) {
|
|
316
|
-
return undefined;
|
|
317
|
-
}
|
|
318
|
-
marketPoolIndexer.coinPrice = coinPrice ?? marketPoolIndexer.coinPrice;
|
|
319
|
-
marketPoolIndexer.coinWrappedType = query.utils.getCoinWrappedType(
|
|
320
|
-
marketPoolIndexer.coinName
|
|
321
|
-
);
|
|
308
|
+
coinPrice =
|
|
309
|
+
coinPrice ||
|
|
310
|
+
(await query.utils.getCoinPrices([poolCoinName]))?.[poolCoinName];
|
|
322
311
|
|
|
323
|
-
|
|
312
|
+
if (indexer) {
|
|
313
|
+
const marketPoolIndexer = await query.indexer.getMarketPool(poolCoinName);
|
|
314
|
+
if (!marketPoolIndexer) {
|
|
315
|
+
return undefined;
|
|
324
316
|
}
|
|
317
|
+
marketPoolIndexer.coinPrice = coinPrice ?? marketPoolIndexer.coinPrice;
|
|
318
|
+
marketPoolIndexer.coinWrappedType = query.utils.getCoinWrappedType(
|
|
319
|
+
marketPoolIndexer.coinName
|
|
320
|
+
);
|
|
325
321
|
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
marketObject ||
|
|
329
|
-
(
|
|
330
|
-
await query.cache.queryGetObject(marketId, {
|
|
331
|
-
showContent: true,
|
|
332
|
-
})
|
|
333
|
-
)?.data;
|
|
322
|
+
return marketPoolIndexer;
|
|
323
|
+
}
|
|
334
324
|
|
|
335
|
-
|
|
336
|
-
|
|
325
|
+
const marketId = query.address.get('core.market');
|
|
326
|
+
marketObject =
|
|
327
|
+
marketObject ||
|
|
328
|
+
(
|
|
329
|
+
await query.cache.queryGetObject(marketId, {
|
|
330
|
+
showContent: true,
|
|
331
|
+
})
|
|
332
|
+
)?.data;
|
|
337
333
|
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
334
|
+
if (!(marketObject && marketObject.content?.dataType === 'moveObject'))
|
|
335
|
+
throw new Error(`Failed to fetch marketObject`);
|
|
336
|
+
|
|
337
|
+
const fields = marketObject.content.fields as any;
|
|
338
|
+
const coinType = query.utils.parseCoinType(poolCoinName);
|
|
339
|
+
// Get balance sheet.
|
|
340
|
+
const balanceSheetParentId =
|
|
341
|
+
fields.vault.fields.balance_sheets.fields.table.fields.id.id;
|
|
342
|
+
const balanceSheetDynamicFieldObjectResponse =
|
|
343
|
+
await query.cache.queryGetDynamicFieldObject({
|
|
344
|
+
parentId: balanceSheetParentId,
|
|
345
|
+
name: {
|
|
346
|
+
type: '0x1::type_name::TypeName',
|
|
347
|
+
value: {
|
|
348
|
+
name: coinType.substring(2),
|
|
351
349
|
},
|
|
352
|
-
}
|
|
350
|
+
},
|
|
351
|
+
});
|
|
353
352
|
|
|
354
|
-
|
|
355
|
-
|
|
353
|
+
const balanceSheetDynamicFieldObject =
|
|
354
|
+
balanceSheetDynamicFieldObjectResponse?.data;
|
|
356
355
|
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
)
|
|
356
|
+
if (
|
|
357
|
+
!(
|
|
358
|
+
balanceSheetDynamicFieldObject &&
|
|
359
|
+
balanceSheetDynamicFieldObject.content &&
|
|
360
|
+
'fields' in balanceSheetDynamicFieldObject.content
|
|
363
361
|
)
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
)
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
},
|
|
362
|
+
)
|
|
363
|
+
throw new Error(
|
|
364
|
+
`Failed to fetch balanceSheetDynamicFieldObject for ${poolCoinName}: ${balanceSheetDynamicFieldObjectResponse?.error?.code.toString()}`
|
|
365
|
+
);
|
|
366
|
+
const balanceSheet: BalanceSheet = (
|
|
367
|
+
balanceSheetDynamicFieldObject.content.fields as any
|
|
368
|
+
).value.fields;
|
|
369
|
+
|
|
370
|
+
// Get borrow index.
|
|
371
|
+
const borrowIndexParentId = fields.borrow_dynamics.fields.table.fields.id.id;
|
|
372
|
+
const borrowIndexDynamicFieldObjectResponse =
|
|
373
|
+
await query.cache.queryGetDynamicFieldObject({
|
|
374
|
+
parentId: borrowIndexParentId,
|
|
375
|
+
name: {
|
|
376
|
+
type: '0x1::type_name::TypeName',
|
|
377
|
+
value: {
|
|
378
|
+
name: coinType.substring(2),
|
|
382
379
|
},
|
|
383
|
-
}
|
|
380
|
+
},
|
|
381
|
+
});
|
|
384
382
|
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
)
|
|
383
|
+
const borrowIndexDynamicFieldObject =
|
|
384
|
+
borrowIndexDynamicFieldObjectResponse?.data;
|
|
385
|
+
if (
|
|
386
|
+
!(
|
|
387
|
+
borrowIndexDynamicFieldObject &&
|
|
388
|
+
borrowIndexDynamicFieldObject.content &&
|
|
389
|
+
'fields' in borrowIndexDynamicFieldObject.content
|
|
393
390
|
)
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
391
|
+
)
|
|
392
|
+
throw new Error(
|
|
393
|
+
`Failed to fetch borrowIndexDynamicFieldObject for ${poolCoinName}`
|
|
394
|
+
);
|
|
395
|
+
const borrowIndex: BorrowIndex = (
|
|
396
|
+
borrowIndexDynamicFieldObject.content.fields as any
|
|
397
|
+
).value.fields;
|
|
398
|
+
|
|
399
|
+
// Get interest models.
|
|
400
|
+
const interestModelParentId =
|
|
401
|
+
fields.interest_models.fields.table.fields.id.id;
|
|
402
|
+
const interestModelDynamicFieldObjectResponse =
|
|
403
|
+
await query.cache.queryGetDynamicFieldObject({
|
|
404
|
+
parentId: interestModelParentId,
|
|
405
|
+
name: {
|
|
406
|
+
type: '0x1::type_name::TypeName',
|
|
407
|
+
value: {
|
|
408
|
+
name: coinType.substring(2),
|
|
409
|
+
},
|
|
410
|
+
},
|
|
411
|
+
});
|
|
412
|
+
|
|
413
|
+
const interestModelDynamicFieldObject =
|
|
414
|
+
interestModelDynamicFieldObjectResponse?.data;
|
|
415
|
+
if (
|
|
416
|
+
!(
|
|
417
|
+
interestModelDynamicFieldObject &&
|
|
418
|
+
interestModelDynamicFieldObject.content &&
|
|
419
|
+
'fields' in interestModelDynamicFieldObject.content
|
|
420
|
+
)
|
|
421
|
+
)
|
|
422
|
+
throw new Error(
|
|
423
|
+
`Failed to fetch interestModelDynamicFieldObject for ${poolCoinName}: ${interestModelDynamicFieldObject}`
|
|
424
|
+
);
|
|
425
|
+
const interestModel: InterestModel = (
|
|
426
|
+
interestModelDynamicFieldObject.content.fields as any
|
|
427
|
+
).value.fields;
|
|
428
|
+
|
|
429
|
+
// Get borrow fee.
|
|
430
|
+
const getBorrowFee = async () => {
|
|
431
|
+
const borrowFeeDynamicFieldObjectResponse =
|
|
405
432
|
await query.cache.queryGetDynamicFieldObject({
|
|
406
|
-
parentId:
|
|
433
|
+
parentId: marketId,
|
|
407
434
|
name: {
|
|
408
|
-
type:
|
|
435
|
+
type: `${BORROW_FEE_PROTOCOL_ID}::market_dynamic_keys::BorrowFeeKey`,
|
|
409
436
|
value: {
|
|
410
|
-
|
|
437
|
+
type: {
|
|
438
|
+
name: coinType.substring(2),
|
|
439
|
+
},
|
|
411
440
|
},
|
|
412
441
|
},
|
|
413
442
|
});
|
|
414
443
|
|
|
415
|
-
const
|
|
416
|
-
|
|
444
|
+
const borrowFeeDynamicFieldObject =
|
|
445
|
+
borrowFeeDynamicFieldObjectResponse?.data;
|
|
417
446
|
if (
|
|
418
447
|
!(
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
'fields' in
|
|
448
|
+
borrowFeeDynamicFieldObject &&
|
|
449
|
+
borrowFeeDynamicFieldObject.content &&
|
|
450
|
+
'fields' in borrowFeeDynamicFieldObject.content
|
|
422
451
|
)
|
|
423
452
|
)
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
const interestModel: InterestModel = (
|
|
428
|
-
interestModelDynamicFieldObject.content.fields as any
|
|
429
|
-
).value.fields;
|
|
430
|
-
|
|
431
|
-
// Get borrow fee.
|
|
432
|
-
const getBorrowFee = async () => {
|
|
433
|
-
const borrowFeeDynamicFieldObjectResponse =
|
|
434
|
-
await query.cache.queryGetDynamicFieldObject({
|
|
435
|
-
parentId: marketId,
|
|
436
|
-
name: {
|
|
437
|
-
type: `${BORROW_FEE_PROTOCOL_ID}::market_dynamic_keys::BorrowFeeKey`,
|
|
438
|
-
value: {
|
|
439
|
-
type: {
|
|
440
|
-
name: coinType.substring(2),
|
|
441
|
-
},
|
|
442
|
-
},
|
|
443
|
-
},
|
|
444
|
-
});
|
|
445
|
-
|
|
446
|
-
const borrowFeeDynamicFieldObject =
|
|
447
|
-
borrowFeeDynamicFieldObjectResponse?.data;
|
|
448
|
-
if (
|
|
449
|
-
!(
|
|
450
|
-
borrowFeeDynamicFieldObject &&
|
|
451
|
-
borrowFeeDynamicFieldObject.content &&
|
|
452
|
-
'fields' in borrowFeeDynamicFieldObject.content
|
|
453
|
-
)
|
|
454
|
-
)
|
|
455
|
-
return { value: '0' };
|
|
456
|
-
return (borrowFeeDynamicFieldObject.content.fields as any).value.fields;
|
|
457
|
-
};
|
|
453
|
+
return { value: '0' };
|
|
454
|
+
return (borrowFeeDynamicFieldObject.content.fields as any).value.fields;
|
|
455
|
+
};
|
|
458
456
|
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
457
|
+
const parsedMarketPoolData = parseOriginMarketPoolData({
|
|
458
|
+
type: interestModel.type.fields,
|
|
459
|
+
maxBorrowRate: interestModel.max_borrow_rate.fields,
|
|
460
|
+
interestRate: borrowIndex.interest_rate.fields,
|
|
461
|
+
interestRateScale: borrowIndex.interest_rate_scale,
|
|
462
|
+
borrowIndex: borrowIndex.borrow_index,
|
|
463
|
+
lastUpdated: borrowIndex.last_updated,
|
|
464
|
+
cash: balanceSheet.cash,
|
|
465
|
+
debt: balanceSheet.debt,
|
|
466
|
+
marketCoinSupply: balanceSheet.market_coin_supply,
|
|
467
|
+
reserve: balanceSheet.revenue,
|
|
468
|
+
reserveFactor: interestModel.revenue_factor.fields,
|
|
469
|
+
borrowWeight: interestModel.borrow_weight.fields,
|
|
470
|
+
borrowFeeRate: await getBorrowFee(),
|
|
471
|
+
baseBorrowRatePerSec: interestModel.base_borrow_rate_per_sec.fields,
|
|
472
|
+
borrowRateOnHighKink: interestModel.borrow_rate_on_high_kink.fields,
|
|
473
|
+
borrowRateOnMidKink: interestModel.borrow_rate_on_mid_kink.fields,
|
|
474
|
+
highKink: interestModel.high_kink.fields,
|
|
475
|
+
midKink: interestModel.mid_kink.fields,
|
|
476
|
+
minBorrowAmount: interestModel.min_borrow_amount,
|
|
477
|
+
});
|
|
480
478
|
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
479
|
+
const calculatedMarketPoolData = calculateMarketPoolData(
|
|
480
|
+
query.utils,
|
|
481
|
+
parsedMarketPoolData
|
|
482
|
+
);
|
|
485
483
|
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
484
|
+
const coinDecimal = query.utils.getCoinDecimal(poolCoinName);
|
|
485
|
+
const maxSupplyCoin = BigNumber(
|
|
486
|
+
(await getSupplyLimit(query.utils, poolCoinName)) ?? '0'
|
|
487
|
+
)
|
|
488
|
+
.shiftedBy(-coinDecimal)
|
|
489
|
+
.toNumber();
|
|
490
|
+
const maxBorrowCoin = BigNumber(
|
|
491
|
+
(await getBorrowLimit(query.utils, poolCoinName)) ?? '0'
|
|
492
|
+
)
|
|
493
|
+
.shiftedBy(-coinDecimal)
|
|
494
|
+
.toNumber();
|
|
497
495
|
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
} catch (e: any) {
|
|
522
|
-
console.error(e.message);
|
|
523
|
-
}
|
|
496
|
+
return {
|
|
497
|
+
coinName: poolCoinName,
|
|
498
|
+
symbol: query.utils.parseSymbol(poolCoinName),
|
|
499
|
+
coinType: query.utils.parseCoinType(poolCoinName),
|
|
500
|
+
marketCoinType: query.utils.parseMarketCoinType(poolCoinName),
|
|
501
|
+
sCoinType: query.utils.parseSCoinType(
|
|
502
|
+
query.utils.parseMarketCoinName(poolCoinName)
|
|
503
|
+
),
|
|
504
|
+
coinWrappedType: query.utils.getCoinWrappedType(poolCoinName),
|
|
505
|
+
coinDecimal,
|
|
506
|
+
coinPrice: coinPrice ?? 0,
|
|
507
|
+
highKink: parsedMarketPoolData.highKink,
|
|
508
|
+
midKink: parsedMarketPoolData.midKink,
|
|
509
|
+
reserveFactor: parsedMarketPoolData.reserveFactor,
|
|
510
|
+
borrowWeight: parsedMarketPoolData.borrowWeight,
|
|
511
|
+
borrowFee: parsedMarketPoolData.borrowFee,
|
|
512
|
+
marketCoinSupplyAmount: parsedMarketPoolData.marketCoinSupplyAmount,
|
|
513
|
+
minBorrowAmount: parsedMarketPoolData.minBorrowAmount,
|
|
514
|
+
maxSupplyCoin,
|
|
515
|
+
maxBorrowCoin,
|
|
516
|
+
isIsolated: await isIsolatedAsset(query.utils, poolCoinName),
|
|
517
|
+
...calculatedMarketPoolData,
|
|
518
|
+
};
|
|
524
519
|
};
|
|
525
520
|
|
|
526
521
|
/**
|
|
@@ -51,10 +51,12 @@ export const getLendings = async (
|
|
|
51
51
|
) as SupportStakeMarketCoins[];
|
|
52
52
|
|
|
53
53
|
const coinPrices = await query.utils.getCoinPrices(poolCoinNames);
|
|
54
|
-
const marketPools = await query.getMarketPools(poolCoinNames,
|
|
54
|
+
const marketPools = await query.getMarketPools(poolCoinNames, {
|
|
55
|
+
indexer,
|
|
55
56
|
coinPrices,
|
|
56
57
|
});
|
|
57
|
-
const spools = await query.getSpools(stakeMarketCoinNames,
|
|
58
|
+
const spools = await query.getSpools(stakeMarketCoinNames, {
|
|
59
|
+
indexer,
|
|
58
60
|
marketPools,
|
|
59
61
|
coinPrices,
|
|
60
62
|
});
|
|
@@ -128,7 +130,8 @@ export const getLending = async (
|
|
|
128
130
|
|
|
129
131
|
marketPool =
|
|
130
132
|
marketPool ??
|
|
131
|
-
(await query.getMarketPool(poolCoinName,
|
|
133
|
+
(await query.getMarketPool(poolCoinName, {
|
|
134
|
+
indexer,
|
|
132
135
|
coinPrice,
|
|
133
136
|
}));
|
|
134
137
|
|
|
@@ -138,16 +141,13 @@ export const getLending = async (
|
|
|
138
141
|
spool =
|
|
139
142
|
(spool ??
|
|
140
143
|
(SUPPORT_SPOOLS as readonly SupportMarketCoins[]).includes(marketCoinName))
|
|
141
|
-
? await query.getSpool(
|
|
142
|
-
marketCoinName as SupportStakeMarketCoins,
|
|
144
|
+
? await query.getSpool(marketCoinName as SupportStakeMarketCoins, {
|
|
143
145
|
indexer,
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
}
|
|
150
|
-
)
|
|
146
|
+
marketPool,
|
|
147
|
+
coinPrices: {
|
|
148
|
+
[poolCoinName]: coinPrice,
|
|
149
|
+
},
|
|
150
|
+
})
|
|
151
151
|
: undefined;
|
|
152
152
|
// some pool does not have spool
|
|
153
153
|
// if (!spool) throw new Error(`Failed to fetch spool for ${poolCoinName}`);
|
|
@@ -311,7 +311,7 @@ export const getObligationAccounts = async (
|
|
|
311
311
|
indexer: boolean = false
|
|
312
312
|
) => {
|
|
313
313
|
const coinPrices = await query.utils.getCoinPrices();
|
|
314
|
-
const market = await query.queryMarket(indexer,
|
|
314
|
+
const market = await query.queryMarket({ indexer, coinPrices });
|
|
315
315
|
const [coinAmounts, obligations] = await Promise.all([
|
|
316
316
|
query.getCoinAmounts(undefined, ownerAddress),
|
|
317
317
|
query.getObligations(ownerAddress),
|
|
@@ -357,7 +357,7 @@ export const getObligationAccount = async (
|
|
|
357
357
|
];
|
|
358
358
|
coinPrices =
|
|
359
359
|
coinPrices ?? (await query.utils.getCoinPrices(collateralAssetCoinNames));
|
|
360
|
-
market = market ?? (await query.queryMarket(indexer,
|
|
360
|
+
market = market ?? (await query.queryMarket({ indexer, coinPrices }));
|
|
361
361
|
coinAmounts =
|
|
362
362
|
coinAmounts ||
|
|
363
363
|
(await query.getCoinAmounts(collateralAssetCoinNames, ownerAddress));
|
|
@@ -365,8 +365,9 @@ export const getObligationAccount = async (
|
|
|
365
365
|
const [obligationQuery, borrowIncentivePools, borrowIncentiveAccounts] =
|
|
366
366
|
await Promise.all([
|
|
367
367
|
query.queryObligation(obligationId),
|
|
368
|
-
query.getBorrowIncentivePools(undefined,
|
|
368
|
+
query.getBorrowIncentivePools(undefined, {
|
|
369
369
|
coinPrices,
|
|
370
|
+
indexer,
|
|
370
371
|
}),
|
|
371
372
|
query.getBorrowIncentiveAccounts(obligationId),
|
|
372
373
|
]);
|
|
@@ -770,7 +771,7 @@ export const getTotalValueLocked = async (
|
|
|
770
771
|
query: ScallopQuery,
|
|
771
772
|
indexer: boolean = false
|
|
772
773
|
) => {
|
|
773
|
-
const market = await query.queryMarket(indexer);
|
|
774
|
+
const market = await query.queryMarket({ indexer });
|
|
774
775
|
|
|
775
776
|
let supplyValue = BigNumber(0);
|
|
776
777
|
let borrowValue = BigNumber(0);
|
|
@@ -139,8 +139,8 @@ export const getSCoinSwapRate = async (
|
|
|
139
139
|
|
|
140
140
|
// Get lending data for both sCoin A and sCoin B
|
|
141
141
|
const marketPools = await Promise.all([
|
|
142
|
-
query.getMarketPool(fromCoinName
|
|
143
|
-
query.getMarketPool(toCoinName
|
|
142
|
+
query.getMarketPool(fromCoinName),
|
|
143
|
+
query.getMarketPool(toCoinName),
|
|
144
144
|
]);
|
|
145
145
|
if (marketPools.some((pool) => !pool))
|
|
146
146
|
throw new Error('Failed to fetch the lendings data');
|
|
@@ -43,7 +43,7 @@ export const getSpools = async (
|
|
|
43
43
|
coinPrices = coinPrices ?? (await query.utils.getCoinPrices()) ?? {};
|
|
44
44
|
|
|
45
45
|
marketPools =
|
|
46
|
-
marketPools ?? (await query.getMarketPools(stakeCoinNames, indexer));
|
|
46
|
+
marketPools ?? (await query.getMarketPools(stakeCoinNames, { indexer }));
|
|
47
47
|
if (!marketPools)
|
|
48
48
|
throw new Error(`Fail to fetch marketPools for ${stakeCoinNames}`);
|
|
49
49
|
|
|
@@ -112,7 +112,7 @@ export const getSpool = async (
|
|
|
112
112
|
coinPrices?: CoinPrices
|
|
113
113
|
) => {
|
|
114
114
|
const coinName = query.utils.parseCoinName<SupportStakeCoins>(marketCoinName);
|
|
115
|
-
marketPool = marketPool || (await query.getMarketPool(coinName, indexer));
|
|
115
|
+
marketPool = marketPool || (await query.getMarketPool(coinName, { indexer }));
|
|
116
116
|
if (!marketPool) {
|
|
117
117
|
throw new Error(`Failed to fetch marketPool for ${marketCoinName}`);
|
|
118
118
|
}
|
package/src/utils/indexer.ts
CHANGED
|
@@ -11,14 +11,20 @@ export async function callMethodWithIndexerFallback(
|
|
|
11
11
|
context: any,
|
|
12
12
|
...args: any[]
|
|
13
13
|
) {
|
|
14
|
-
const
|
|
14
|
+
const lastArgs = args[args.length - 1]; // Assume last argument is always `indexer`
|
|
15
15
|
|
|
16
|
-
if (indexer) {
|
|
16
|
+
if (typeof lastArgs === 'object' && lastArgs.indexer) {
|
|
17
17
|
try {
|
|
18
18
|
return await method.apply(context, args);
|
|
19
19
|
} catch (e: any) {
|
|
20
20
|
console.warn(`Indexer requests failed: ${e}. Retrying without indexer..`);
|
|
21
|
-
return await method.apply(context, [
|
|
21
|
+
return await method.apply(context, [
|
|
22
|
+
...args.slice(0, -1),
|
|
23
|
+
{
|
|
24
|
+
...lastArgs,
|
|
25
|
+
indexer: false,
|
|
26
|
+
},
|
|
27
|
+
]);
|
|
22
28
|
}
|
|
23
29
|
}
|
|
24
30
|
return await method.apply(context, args);
|
package/src/utils/tokenBucket.ts
CHANGED
|
@@ -38,8 +38,8 @@ const callWithRateLimit = async <T>(
|
|
|
38
38
|
tokenBucket: TokenBucket,
|
|
39
39
|
fn: () => Promise<T>,
|
|
40
40
|
retryDelayInMs = DEFAULT_INTERVAL_IN_MS,
|
|
41
|
-
maxRetries =
|
|
42
|
-
backoffFactor =
|
|
41
|
+
maxRetries = 15,
|
|
42
|
+
backoffFactor = 2 // The factor by which to increase the delay
|
|
43
43
|
): Promise<T | null> => {
|
|
44
44
|
let retries = 0;
|
|
45
45
|
|