@scallop-io/sui-scallop-sdk 1.3.3 → 1.3.4-alpha.2

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.
Files changed (103) hide show
  1. package/dist/index.js +1258 -1092
  2. package/dist/index.js.map +1 -1
  3. package/dist/index.mjs +1249 -1092
  4. package/dist/index.mjs.map +1 -1
  5. package/package.json +2 -2
  6. package/src/builders/loyaltyProgramBuilder.ts +1 -1
  7. package/src/constants/coinGecko.ts +18 -0
  8. package/src/constants/common.ts +0 -1
  9. package/src/constants/enum.ts +8 -0
  10. package/src/constants/index.ts +6 -0
  11. package/src/constants/poolAddress.ts +94 -0
  12. package/src/constants/pyth.ts +19 -0
  13. package/src/constants/queryKeys.ts +1 -5
  14. package/src/constants/rpc.ts +16 -0
  15. package/src/constants/tokenBucket.ts +1 -1
  16. package/src/models/scallop.ts +3 -2
  17. package/src/models/scallopAddress.ts +2 -2
  18. package/src/models/scallopBuilder.ts +4 -3
  19. package/src/models/scallopCache.ts +1 -1
  20. package/src/models/scallopClient.ts +27 -26
  21. package/src/models/scallopQuery.ts +58 -15
  22. package/src/models/scallopUtils.ts +96 -96
  23. package/src/models/suiKit.ts +11 -0
  24. package/src/queries/borrowIncentiveQuery.ts +6 -13
  25. package/src/queries/coreQuery.ts +37 -22
  26. package/src/queries/loyaltyProgramQuery.ts +1 -1
  27. package/src/queries/portfolioQuery.ts +55 -34
  28. package/src/queries/spoolQuery.ts +17 -17
  29. package/src/types/utils.ts +13 -0
  30. package/src/utils/tokenBucket.ts +2 -1
  31. package/src/utils/util.ts +2 -1
  32. package/dist/builders/borrowIncentiveBuilder.d.ts +0 -12
  33. package/dist/builders/coreBuilder.d.ts +0 -12
  34. package/dist/builders/index.d.ts +0 -12
  35. package/dist/builders/loyaltyProgramBuilder.d.ts +0 -12
  36. package/dist/builders/oracle.d.ts +0 -14
  37. package/dist/builders/referralBuilder.d.ts +0 -12
  38. package/dist/builders/sCoinBuilder.d.ts +0 -4
  39. package/dist/builders/spoolBuilder.d.ts +0 -12
  40. package/dist/builders/vescaBuilder.d.ts +0 -25
  41. package/dist/constants/cache.d.ts +0 -14
  42. package/dist/constants/common.d.ts +0 -20
  43. package/dist/constants/enum.d.ts +0 -13
  44. package/dist/constants/flashloan.d.ts +0 -2
  45. package/dist/constants/index.d.ts +0 -5
  46. package/dist/constants/pyth.d.ts +0 -3
  47. package/dist/constants/queryKeys.d.ts +0 -58
  48. package/dist/constants/testAddress.d.ts +0 -2
  49. package/dist/constants/tokenBucket.d.ts +0 -2
  50. package/dist/constants/vesca.d.ts +0 -5
  51. package/dist/index.d.ts +0 -3
  52. package/dist/models/index.d.ts +0 -8
  53. package/dist/models/scallop.d.ts +0 -74
  54. package/dist/models/scallopAddress.d.ts +0 -150
  55. package/dist/models/scallopBuilder.d.ts +0 -89
  56. package/dist/models/scallopCache.d.ts +0 -74
  57. package/dist/models/scallopClient.d.ts +0 -321
  58. package/dist/models/scallopIndexer.d.ts +0 -89
  59. package/dist/models/scallopPrice.d.ts +0 -0
  60. package/dist/models/scallopQuery.d.ts +0 -474
  61. package/dist/models/scallopUtils.d.ts +0 -217
  62. package/dist/queries/borrowIncentiveQuery.d.ts +0 -61
  63. package/dist/queries/coreQuery.d.ts +0 -167
  64. package/dist/queries/index.d.ts +0 -8
  65. package/dist/queries/isolatedAsset.d.ts +0 -14
  66. package/dist/queries/loyaltyProgramQuery.d.ts +0 -10
  67. package/dist/queries/portfolioQuery.d.ts +0 -73
  68. package/dist/queries/priceQuery.d.ts +0 -16
  69. package/dist/queries/referralQuery.d.ts +0 -7
  70. package/dist/queries/sCoinQuery.d.ts +0 -41
  71. package/dist/queries/spoolQuery.d.ts +0 -70
  72. package/dist/queries/supplyLimit.d.ts +0 -9
  73. package/dist/queries/vescaQuery.d.ts +0 -36
  74. package/dist/types/address.d.ts +0 -107
  75. package/dist/types/builder/borrowIncentive.d.ts +0 -35
  76. package/dist/types/builder/core.d.ts +0 -56
  77. package/dist/types/builder/index.d.ts +0 -24
  78. package/dist/types/builder/loyaltyProgram.d.ts +0 -23
  79. package/dist/types/builder/referral.d.ts +0 -30
  80. package/dist/types/builder/sCoin.d.ts +0 -37
  81. package/dist/types/builder/spool.d.ts +0 -29
  82. package/dist/types/builder/vesca.d.ts +0 -51
  83. package/dist/types/constant/common.d.ts +0 -24
  84. package/dist/types/constant/enum.d.ts +0 -48
  85. package/dist/types/constant/index.d.ts +0 -2
  86. package/dist/types/index.d.ts +0 -6
  87. package/dist/types/model.d.ts +0 -54
  88. package/dist/types/query/borrowIncentive.d.ts +0 -124
  89. package/dist/types/query/core.d.ts +0 -361
  90. package/dist/types/query/index.d.ts +0 -7
  91. package/dist/types/query/loyaltyProgram.d.ts +0 -5
  92. package/dist/types/query/portfolio.d.ts +0 -115
  93. package/dist/types/query/sCoin.d.ts +0 -1
  94. package/dist/types/query/spool.d.ts +0 -122
  95. package/dist/types/query/vesca.d.ts +0 -26
  96. package/dist/types/utils.d.ts +0 -9
  97. package/dist/utils/builder.d.ts +0 -15
  98. package/dist/utils/index.d.ts +0 -5
  99. package/dist/utils/indexer.d.ts +0 -17
  100. package/dist/utils/query.d.ts +0 -62
  101. package/dist/utils/tokenBucket.d.ts +0 -11
  102. package/dist/utils/util.d.ts +0 -26
  103. package/src/models/scallopPrice.ts +0 -0
@@ -47,6 +47,9 @@ import {
47
47
  SupportBorrowIncentiveCoins,
48
48
  SupportSCoin,
49
49
  ScallopQueryInstanceParams,
50
+ MarketPool,
51
+ CoinPrices,
52
+ MarketPools,
50
53
  } from '../types';
51
54
  import { ScallopAddress } from './scallopAddress';
52
55
  import { ScallopUtils } from './scallopUtils';
@@ -64,6 +67,7 @@ import { normalizeSuiAddress } from '@mysten/sui/utils';
64
67
  import { getSupplyLimit } from 'src/queries/supplyLimit';
65
68
  import { withIndexerFallback } from 'src/utils/indexer';
66
69
  import { getIsolatedAssets, isIsolatedAsset } from 'src/queries/isolatedAsset';
70
+ import { newSuiKit } from './suiKit';
67
71
 
68
72
  /**
69
73
  * @description
@@ -93,10 +97,10 @@ export class ScallopQuery {
93
97
  ) {
94
98
  this.params = params;
95
99
  this.suiKit =
96
- instance?.suiKit ?? instance?.utils?.suiKit ?? new SuiKit(params);
100
+ instance?.suiKit ?? instance?.utils?.suiKit ?? newSuiKit(params);
97
101
 
98
102
  this.walletAddress = normalizeSuiAddress(
99
- params.walletAddress || this.suiKit.currentAddress()
103
+ params.walletAddress ?? this.suiKit.currentAddress()
100
104
  );
101
105
 
102
106
  if (instance?.utils) {
@@ -111,7 +115,7 @@ export class ScallopQuery {
111
115
  );
112
116
  this.address = new ScallopAddress(
113
117
  {
114
- id: params?.addressesId || ADDRESSES_ID,
118
+ id: params?.addressesId ?? ADDRESSES_ID,
115
119
  network: params?.networkType,
116
120
  forceInterface: params?.forceAddressesInterface,
117
121
  },
@@ -183,8 +187,11 @@ export class ScallopQuery {
183
187
  * @param indexer - Whether to use indexer.
184
188
  * @return Market data.
185
189
  */
186
- public async queryMarket(indexer: boolean = false) {
187
- return await queryMarket(this, indexer);
190
+ public async queryMarket(
191
+ indexer: boolean = false,
192
+ args?: { coinPrices: CoinPrices }
193
+ ) {
194
+ return await queryMarket(this, indexer, args?.coinPrices);
188
195
  }
189
196
 
190
197
  /**
@@ -200,9 +207,12 @@ export class ScallopQuery {
200
207
  */
201
208
  public async getMarketPools(
202
209
  poolCoinNames?: SupportPoolCoins[],
203
- indexer: boolean = false
210
+ indexer: boolean = false,
211
+ args?: {
212
+ coinPrices?: CoinPrices;
213
+ }
204
214
  ) {
205
- return await getMarketPools(this, poolCoinNames, indexer);
215
+ return await getMarketPools(this, poolCoinNames, indexer, args?.coinPrices);
206
216
  }
207
217
 
208
218
  /**
@@ -214,9 +224,19 @@ export class ScallopQuery {
214
224
  */
215
225
  public async getMarketPool(
216
226
  poolCoinName: SupportPoolCoins,
217
- indexer: boolean = false
227
+ indexer: boolean = false,
228
+ args?: {
229
+ marketObject?: SuiObjectData | null;
230
+ coinPrice?: number;
231
+ }
218
232
  ) {
219
- return await getMarketPool(this, poolCoinName, indexer);
233
+ return await getMarketPool(
234
+ this,
235
+ poolCoinName,
236
+ indexer,
237
+ args?.marketObject,
238
+ args?.coinPrice
239
+ );
220
240
  }
221
241
 
222
242
  /**
@@ -358,9 +378,19 @@ export class ScallopQuery {
358
378
  */
359
379
  public async getSpools(
360
380
  stakeMarketCoinNames?: SupportStakeMarketCoins[],
361
- indexer: boolean = false
381
+ indexer: boolean = false,
382
+ args?: {
383
+ marketPools?: MarketPools;
384
+ coinPrices?: CoinPrices;
385
+ }
362
386
  ) {
363
- return await getSpools(this, stakeMarketCoinNames, indexer);
387
+ return await getSpools(
388
+ this,
389
+ stakeMarketCoinNames,
390
+ indexer,
391
+ args?.marketPools,
392
+ args?.coinPrices
393
+ );
364
394
  }
365
395
 
366
396
  /**
@@ -372,9 +402,16 @@ export class ScallopQuery {
372
402
  */
373
403
  public async getSpool(
374
404
  stakeMarketCoinName: SupportStakeMarketCoins,
375
- indexer: boolean = false
405
+ indexer: boolean = false,
406
+ args?: { marketPool?: MarketPool; coinPrices?: CoinPrices }
376
407
  ) {
377
- return await getSpool(this, stakeMarketCoinName, indexer);
408
+ return await getSpool(
409
+ this,
410
+ stakeMarketCoinName,
411
+ indexer,
412
+ args?.marketPool,
413
+ args?.coinPrices
414
+ );
378
415
  }
379
416
 
380
417
  /**
@@ -495,9 +532,15 @@ export class ScallopQuery {
495
532
  */
496
533
  public async getBorrowIncentivePools(
497
534
  coinNames?: SupportBorrowIncentiveCoins[],
498
- indexer: boolean = false
535
+ indexer: boolean = false,
536
+ args?: { coinPrices: CoinPrices }
499
537
  ) {
500
- return await getBorrowIncentivePools(this, coinNames, indexer);
538
+ return await getBorrowIncentivePools(
539
+ this,
540
+ coinNames,
541
+ indexer,
542
+ args?.coinPrices
543
+ );
501
544
  }
502
545
 
503
546
  /**
@@ -18,8 +18,11 @@ import {
18
18
  SUPPORT_SCOIN,
19
19
  sCoinIds,
20
20
  suiBridgeCoins,
21
+ COIN_GECKGO_IDS,
22
+ POOL_ADDRESSES,
23
+ sCoinTypeToName,
21
24
  } from '../constants';
22
- import { getPythPrice, queryObligation } from '../queries';
25
+ import { getPythPrices, queryObligation } from '../queries';
23
26
  import {
24
27
  parseDataFromPythPriceFeed,
25
28
  isMarketCoin,
@@ -28,7 +31,7 @@ import {
28
31
  isSuiBridgeAsset,
29
32
  isWormholeAsset,
30
33
  } from '../utils';
31
- import { PYTH_ENDPOINTS } from 'src/constants/pyth';
34
+ import { PYTH_ENDPOINTS, PYTH_FEED_IDS } from 'src/constants/pyth';
32
35
  import { ScallopCache } from './scallopCache';
33
36
  import { DEFAULT_CACHE_OPTIONS } from 'src/constants/cache';
34
37
  import type {
@@ -39,15 +42,16 @@ import type {
39
42
  SupportStakeMarketCoins,
40
43
  SupportBorrowIncentiveCoins,
41
44
  CoinPrices,
42
- PriceMap,
43
45
  CoinWrappedType,
44
46
  SupportSCoin,
45
47
  ScallopUtilsInstanceParams,
46
48
  SupportSuiBridgeCoins,
47
49
  SupportWormholeCoins,
50
+ PoolAddressInfo,
48
51
  } from '../types';
49
52
  import { queryKeys } from 'src/constants';
50
53
  import type { SuiObjectArg, SuiTxArg, SuiTxBlock } from '@scallop-io/sui-kit';
54
+ import { newSuiKit } from './suiKit';
51
55
 
52
56
  /**
53
57
  * @description
@@ -69,7 +73,6 @@ export class ScallopUtils {
69
73
  public address: ScallopAddress;
70
74
  public cache: ScallopCache;
71
75
  public walletAddress: string;
72
- private _priceMap: PriceMap = new Map();
73
76
 
74
77
  public constructor(
75
78
  params: ScallopUtilsParams,
@@ -80,9 +83,7 @@ export class ScallopUtils {
80
83
  ...params,
81
84
  };
82
85
  this.suiKit =
83
- instance?.suiKit ??
84
- instance?.address?.cache._suiKit ??
85
- new SuiKit(params);
86
+ instance?.suiKit ?? instance?.address?.cache._suiKit ?? newSuiKit(params);
86
87
 
87
88
  this.walletAddress = params.walletAddress ?? this.suiKit.currentAddress();
88
89
 
@@ -100,7 +101,7 @@ export class ScallopUtils {
100
101
  instance?.address ??
101
102
  new ScallopAddress(
102
103
  {
103
- id: params?.addressesId || ADDRESSES_ID,
104
+ id: params?.addressesId ?? ADDRESSES_ID,
104
105
  network: params?.networkType,
105
106
  forceInterface: params?.forceAddressesInterface,
106
107
  },
@@ -224,6 +225,7 @@ export class ScallopUtils {
224
225
  return undefined;
225
226
  }
226
227
  }
228
+
227
229
  /**
228
230
  * Convert sCoin name into sCoin type
229
231
  * @param sCoinName
@@ -233,6 +235,15 @@ export class ScallopUtils {
233
235
  return sCoinIds[sCoinName];
234
236
  }
235
237
 
238
+ /**
239
+ * Convert sCoinType into sCoin name
240
+ * @param sCoinType
241
+ * @returns sCoin name
242
+ */
243
+ public parseSCoinNameFromType(sCoinType: string) {
244
+ return sCoinTypeToName[sCoinType];
245
+ }
246
+
236
247
  /**
237
248
  * Convert sCoin name into its underlying coin type
238
249
  * @param sCoinName
@@ -261,7 +272,7 @@ export class ScallopUtils {
261
272
  */
262
273
  public parseMarketCoinType(coinName: SupportCoins) {
263
274
  const protocolObjectId =
264
- this.address.get('core.object') || PROTOCOL_OBJECT_ID;
275
+ this.address.get('core.object') ?? PROTOCOL_OBJECT_ID;
265
276
  const coinType = this.parseCoinType(coinName);
266
277
  return `${protocolObjectId}::reserve::MarketCoin<${coinType}>`;
267
278
  }
@@ -290,7 +301,7 @@ export class ScallopUtils {
290
301
  const coinTypeRegex = new RegExp(`((0x[^:]+::[^:]+::[^<>]+))(?![^<>]*<)`);
291
302
  const coinTypeMatch = coinType.match(coinTypeRegex);
292
303
  const isMarketCoinType = coinType.includes('reserve::MarketCoin');
293
- coinType = coinTypeMatch?.[1] || coinType;
304
+ coinType = coinTypeMatch?.[1] ?? coinType;
294
305
 
295
306
  const wormHoleCoinTypeMap: Record<string, SupportAssetCoins> = {
296
307
  [`${
@@ -428,7 +439,7 @@ export class ScallopUtils {
428
439
  coinType: string = SUI_TYPE_ARG,
429
440
  ownerAddress?: string
430
441
  ) {
431
- ownerAddress = ownerAddress || this.suiKit.currentAddress();
442
+ ownerAddress = ownerAddress ?? this.suiKit.currentAddress();
432
443
  const coins = await this.suiKit.suiInteractor.selectCoins(
433
444
  ownerAddress,
434
445
  amount,
@@ -508,100 +519,68 @@ export class ScallopUtils {
508
519
  * @return Asset coin price.
509
520
  */
510
521
  public async getCoinPrices(
511
- assetCoinNames: SupportAssetCoins[] = [
522
+ _: SupportAssetCoins[] = [
512
523
  ...new Set([...SUPPORT_POOLS, ...SUPPORT_COLLATERALS]),
513
524
  ] as SupportAssetCoins[]
514
525
  ) {
515
- const coinPrices: CoinPrices = {};
516
- const existPricesCoinNames: SupportAssetCoins[] = [];
517
- const lackPricesCoinNames: SupportAssetCoins[] = [];
518
-
519
- assetCoinNames.forEach((assetCoinName) => {
520
- if (
521
- this._priceMap.has(assetCoinName) &&
522
- Date.now() - this._priceMap.get(assetCoinName)!.publishTime < 1000 * 60
523
- ) {
524
- existPricesCoinNames.push(assetCoinName);
525
- } else {
526
- lackPricesCoinNames.push(assetCoinName);
527
- this.cache.queryClient.invalidateQueries({
528
- queryKey: queryKeys.oracle.getPythLatestPriceFeed(
529
- this.address.get(`core.coins.${assetCoinName}.oracle.pyth.feed`)
530
- ),
531
- });
532
- }
533
- });
534
-
535
- if (existPricesCoinNames.length > 0) {
536
- for (const coinName of existPricesCoinNames) {
537
- coinPrices[coinName] = this._priceMap.get(coinName)!.price;
538
- }
539
- }
526
+ let coinPrices: CoinPrices = {};
527
+
528
+ const endpoints =
529
+ this.params.pythEndpoints ??
530
+ PYTH_ENDPOINTS[this.isTestnet ? 'testnet' : 'mainnet'];
531
+
532
+ const failedRequests: Set<SupportAssetCoins> = new Set([
533
+ ...SUPPORT_POOLS,
534
+ ...SUPPORT_COLLATERALS,
535
+ ]);
536
+
537
+ for (const endpoint of endpoints) {
538
+ const priceIdPairs = Array.from(failedRequests.values()).reduce(
539
+ (acc, coinName) => {
540
+ const priceId = this.address.get(
541
+ `core.coins.${coinName}.oracle.pyth.feed`
542
+ );
543
+ acc.push([coinName, priceId]);
544
+ return acc;
545
+ },
546
+ [] as [string, string][]
547
+ );
540
548
 
541
- if (lackPricesCoinNames.length > 0) {
542
- const endpoints =
543
- this.params.pythEndpoints ??
544
- PYTH_ENDPOINTS[this.isTestnet ? 'testnet' : 'mainnet'];
549
+ const priceIds = priceIdPairs.map(([_, priceId]) => priceId);
545
550
 
546
- const failedRequests: Set<SupportAssetCoins> = new Set(
547
- lackPricesCoinNames
548
- );
551
+ const pythConnection = new SuiPriceServiceConnection(endpoint, {
552
+ timeout: 2000,
553
+ });
549
554
 
550
- for (const endpoint of endpoints) {
551
- const priceIds = Array.from(failedRequests.values()).reduce(
552
- (acc, coinName) => {
553
- const priceId = this.address.get(
554
- `core.coins.${coinName}.oracle.pyth.feed`
555
- );
556
- acc[coinName] = priceId;
557
- return acc;
555
+ try {
556
+ const feeds = await this.cache.queryClient.fetchQuery({
557
+ queryKey: queryKeys.oracle.getPythLatestPriceFeeds(),
558
+ queryFn: async () => {
559
+ return await pythConnection.getLatestPriceFeeds(priceIds);
558
560
  },
559
- {} as Record<SupportAssetCoins, string>
560
- );
561
-
562
- await Promise.allSettled(
563
- Object.entries(priceIds).map(async ([coinName, priceId]) => {
564
- const pythConnection = new SuiPriceServiceConnection(endpoint);
565
- try {
566
- const feed = await this.cache.queryClient.fetchQuery({
567
- queryKey: queryKeys.oracle.getPythLatestPriceFeed(priceId),
568
- queryFn: async () => {
569
- return (
570
- (await pythConnection.getLatestPriceFeeds([priceId])) ?? []
571
- );
572
- },
573
- });
574
- if (feed[0]) {
575
- const data = parseDataFromPythPriceFeed(feed[0], this.address);
576
- this._priceMap.set(coinName as SupportAssetCoins, {
577
- price: data.price,
578
- publishTime: data.publishTime,
579
- });
580
- coinPrices[coinName as SupportAssetCoins] = data.price;
581
- }
582
- failedRequests.delete(coinName as SupportAssetCoins); // remove success price feed to prevent duplicate request on the next endpoint
583
- } catch (e) {
584
- console.warn(
585
- `Failed to get price ${coinName} feeds with endpoint ${endpoint}: ${e}`
586
- );
587
- }
588
- })
589
- );
590
- if (failedRequests.size === 0) break;
561
+ staleTime: 30000,
562
+ gcTime: 30000,
563
+ });
564
+ if (feeds) {
565
+ feeds.forEach((feed, idx) => {
566
+ const coinName = priceIdPairs[idx][0] as SupportAssetCoins;
567
+ const data = parseDataFromPythPriceFeed(feed, this.address);
568
+ coinPrices[coinName as SupportAssetCoins] = data.price;
569
+ failedRequests.delete(coinName as SupportAssetCoins); // remove success price feed to prevent duplicate request on the next endpoint
570
+ });
571
+ }
572
+ } catch (e: any) {
573
+ console.error(e.message);
591
574
  }
575
+ if (failedRequests.size === 0) break;
576
+ }
592
577
 
593
- if (failedRequests.size > 0) {
594
- await Promise.allSettled(
595
- Array.from(failedRequests.values()).map(async (coinName) => {
596
- const price = await getPythPrice(this, coinName);
597
- this._priceMap.set(coinName, {
598
- price: price,
599
- publishTime: Date.now(),
600
- });
601
- coinPrices[coinName] = price;
602
- })
603
- );
604
- }
578
+ if (failedRequests.size > 0) {
579
+ coinPrices = {
580
+ ...coinPrices,
581
+ ...(await getPythPrices(this, Array.from(failedRequests.values()))),
582
+ };
583
+ failedRequests.clear();
605
584
  }
606
585
 
607
586
  return coinPrices;
@@ -670,4 +649,25 @@ export class ScallopUtils {
670
649
  }
671
650
  return findClosestUnlockRound(newUnlockAtInSecondTimestamp);
672
651
  }
652
+
653
+ /**
654
+ * Get detailed contract address and price id information for supported pool in Scallop
655
+ * @returns Supported pool informations
656
+ */
657
+ public getSupportedPoolAddresses(): PoolAddressInfo[] {
658
+ return SUPPORT_POOLS.map((poolName) => {
659
+ const sCoinName = this.parseSCoinName(poolName)!;
660
+ return {
661
+ name: this.parseSymbol(poolName),
662
+ coingeckoId: COIN_GECKGO_IDS[poolName],
663
+ decimal: coinDecimals[poolName],
664
+ pythFeedId: PYTH_FEED_IDS[poolName],
665
+ ...POOL_ADDRESSES[poolName],
666
+ sCoinAddress: sCoinIds[sCoinName],
667
+ marketCoinAddress: this.parseMarketCoinType(poolName),
668
+ coinAddress: this.parseCoinType(poolName),
669
+ sCoinName: sCoinName ? this.parseSymbol(sCoinName) : undefined,
670
+ };
671
+ });
672
+ }
673
673
  }
@@ -0,0 +1,11 @@
1
+ import { SuiKit, SuiKitParams } from '@scallop-io/sui-kit';
2
+ import { RPC_PROVIDERS } from 'src/constants/rpc';
3
+
4
+ export const newSuiKit = (params: SuiKitParams) => {
5
+ return new SuiKit({
6
+ ...params,
7
+ fullnodeUrls: Array.from(
8
+ new Set([...(params.fullnodeUrls ?? []), ...RPC_PROVIDERS])
9
+ ),
10
+ });
11
+ };
@@ -1,8 +1,5 @@
1
1
  import { normalizeStructTag } from '@mysten/sui/utils';
2
- import {
3
- SUPPORT_BORROW_INCENTIVE_POOLS,
4
- SUPPORT_BORROW_INCENTIVE_REWARDS,
5
- } from '../constants';
2
+ import { SUPPORT_BORROW_INCENTIVE_POOLS } from '../constants';
6
3
  import {
7
4
  parseOriginBorrowIncentivePoolData,
8
5
  parseOriginBorrowIncentiveAccountData,
@@ -19,6 +16,7 @@ import type {
19
16
  BorrowIncentivePoolPoints,
20
17
  OptionalKeys,
21
18
  BorrowIncentivePool,
19
+ CoinPrices,
22
20
  } from '../types';
23
21
  import BigNumber from 'bignumber.js';
24
22
 
@@ -56,17 +54,12 @@ export const getBorrowIncentivePools = async (
56
54
  borrowIncentiveCoinNames: SupportBorrowIncentiveCoins[] = [
57
55
  ...SUPPORT_BORROW_INCENTIVE_POOLS,
58
56
  ],
59
- indexer: boolean = false
57
+ indexer: boolean = false,
58
+ coinPrices?: CoinPrices
60
59
  ) => {
61
60
  const borrowIncentivePools: BorrowIncentivePools = {};
62
61
 
63
- const coinPrices =
64
- (await query.utils.getCoinPrices([
65
- ...new Set([
66
- ...borrowIncentiveCoinNames,
67
- ...SUPPORT_BORROW_INCENTIVE_REWARDS,
68
- ]),
69
- ])) ?? {};
62
+ coinPrices = coinPrices ?? (await query.utils.getCoinPrices()) ?? {};
70
63
 
71
64
  if (indexer) {
72
65
  const borrowIncentivePoolsIndexer =
@@ -74,7 +67,7 @@ export const getBorrowIncentivePools = async (
74
67
 
75
68
  const updateBorrowIncentivePool = (pool: BorrowIncentivePool) => {
76
69
  if (!borrowIncentiveCoinNames.includes(pool.coinName)) return;
77
- pool.coinPrice = coinPrices[pool.coinName] || pool.coinPrice;
70
+ pool.coinPrice = coinPrices[pool.coinName] ?? pool.coinPrice;
78
71
  borrowIncentivePools[pool.coinName] = pool;
79
72
  };
80
73