@scallop-io/sui-scallop-sdk 0.46.64 → 0.46.66

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.
@@ -1,5 +1,5 @@
1
1
  import type { ScallopAddress, ScallopQuery, ScallopUtils } from '../models';
2
- import type { SupportBorrowIncentiveCoins } from '../types';
2
+ import type { SupportBorrowIncentiveCoins, BorrowIncentivePool } from '../types';
3
3
  /**
4
4
  * Query borrow incentive pools data.
5
5
  *
@@ -9,14 +9,14 @@ import type { SupportBorrowIncentiveCoins } from '../types';
9
9
  * @return Borrow incentive pools data.
10
10
  */
11
11
  export declare const queryBorrowIncentivePools: (query: ScallopQuery, borrowIncentiveCoinNames?: SupportBorrowIncentiveCoins[], indexer?: boolean) => Promise<{
12
- eth?: import("../types").BorrowIncentivePool | undefined;
13
- usdc?: import("../types").BorrowIncentivePool | undefined;
14
- usdt?: import("../types").BorrowIncentivePool | undefined;
15
- sui?: import("../types").BorrowIncentivePool | undefined;
16
- afsui?: import("../types").BorrowIncentivePool | undefined;
17
- hasui?: import("../types").BorrowIncentivePool | undefined;
18
- vsui?: import("../types").BorrowIncentivePool | undefined;
19
- sca?: import("../types").BorrowIncentivePool | undefined;
12
+ eth?: BorrowIncentivePool | undefined;
13
+ usdc?: BorrowIncentivePool | undefined;
14
+ usdt?: BorrowIncentivePool | undefined;
15
+ sui?: BorrowIncentivePool | undefined;
16
+ afsui?: BorrowIncentivePool | undefined;
17
+ hasui?: BorrowIncentivePool | undefined;
18
+ vsui?: BorrowIncentivePool | undefined;
19
+ sca?: BorrowIncentivePool | undefined;
20
20
  }>;
21
21
  /**
22
22
  * Query borrow incentive accounts data.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scallop-io/sui-scallop-sdk",
3
- "version": "0.46.64",
3
+ "version": "0.46.66",
4
4
  "description": "Typescript sdk for interacting with Scallop contract on SUI",
5
5
  "keywords": [
6
6
  "sui",
@@ -392,7 +392,7 @@ const generateCoreQuickMethod: GenerateCoreQuickMethod = ({
392
392
  (await builder.utils.getObligationCoinNames(
393
393
  obligationInfo.obligationId
394
394
  )) ?? [];
395
- const updateCoinNames = [...(obligationCoinNames ?? []), poolCoinName];
395
+ const updateCoinNames = [...obligationCoinNames, poolCoinName];
396
396
  await updateOracles(builder, txBlock, updateCoinNames);
397
397
  return txBlock.borrow(
398
398
  obligationInfo.obligationId,
@@ -32,6 +32,8 @@ export const SCA_COIN_TYPE = IS_VE_SCA_TEST
32
32
  export const OLD_BORROW_INCENTIVE_PROTOCOL_ID =
33
33
  '0xc63072e7f5f4983a2efaf5bdba1480d5e7d74d57948e1c7cc436f8e22cbeb410' as const;
34
34
 
35
+ export const NATIVE_USDC =
36
+ '0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC' as const;
35
37
  export const SUPPORT_POOLS = [
36
38
  'eth',
37
39
  'btc',
@@ -18,6 +18,7 @@ import type {
18
18
  SupportBorrowIncentiveRewardCoins,
19
19
  BorrowIncentivePoolPoints,
20
20
  OptionalKeys,
21
+ BorrowIncentivePool,
21
22
  } from '../types';
22
23
  import BigNumber from 'bignumber.js';
23
24
 
@@ -31,39 +32,35 @@ import BigNumber from 'bignumber.js';
31
32
  */
32
33
  export const queryBorrowIncentivePools = async (
33
34
  query: ScallopQuery,
34
- borrowIncentiveCoinNames?: SupportBorrowIncentiveCoins[],
35
+ borrowIncentiveCoinNames: SupportBorrowIncentiveCoins[] = [
36
+ ...SUPPORT_BORROW_INCENTIVE_POOLS,
37
+ ],
35
38
  indexer: boolean = false
36
39
  ) => {
37
- borrowIncentiveCoinNames = borrowIncentiveCoinNames || [
38
- ...SUPPORT_BORROW_INCENTIVE_POOLS,
39
- ];
40
-
41
40
  const borrowIncentivePools: BorrowIncentivePools = {};
42
41
 
43
- const coinPrices = await query.utils.getCoinPrices(
44
- [
42
+ const coinPrices =
43
+ (await query.utils.getCoinPrices([
45
44
  ...new Set([
46
45
  ...borrowIncentiveCoinNames,
47
46
  ...SUPPORT_BORROW_INCENTIVE_REWARDS,
48
47
  ]),
49
- ] ?? []
50
- );
48
+ ])) ?? {};
51
49
 
52
50
  if (indexer) {
53
51
  const borrowIncentivePoolsIndexer =
54
52
  await query.indexer.getBorrowIncentivePools();
55
- for (const borrowIncentivePool of Object.values(
56
- borrowIncentivePoolsIndexer
57
- )) {
58
- if (!borrowIncentiveCoinNames.includes(borrowIncentivePool.coinName))
59
- continue;
60
- borrowIncentivePool.coinPrice =
61
- coinPrices[borrowIncentivePool.coinName] ||
62
- borrowIncentivePool.coinPrice;
63
- // borrowIncentivePool.rewardCoinPrice =
64
- // coinPrices[rewardCoinName] || borrowIncentivePool.rewardCoinPrice;
65
- borrowIncentivePools[borrowIncentivePool.coinName] = borrowIncentivePool;
66
- }
53
+
54
+ const updateBorrowIncentivePool = (pool: BorrowIncentivePool) => {
55
+ if (!borrowIncentiveCoinNames.includes(pool.coinName)) return;
56
+ pool.coinPrice = coinPrices[pool.coinName] || pool.coinPrice;
57
+ borrowIncentivePools[pool.coinName] = pool;
58
+ };
59
+
60
+ Object.values(borrowIncentivePoolsIndexer).forEach(
61
+ updateBorrowIncentivePool
62
+ );
63
+
67
64
  return borrowIncentivePools;
68
65
  }
69
66
 
@@ -6,6 +6,7 @@ import {
6
6
  BORROW_FEE_PROTOCOL_ID,
7
7
  USE_TEST_ADDRESS,
8
8
  FlashLoanFeeObjectMap,
9
+ NATIVE_USDC,
9
10
  } from '../constants';
10
11
  import {
11
12
  parseOriginMarketPoolData,
@@ -60,20 +61,25 @@ export const queryMarket = async (
60
61
 
61
62
  if (indexer) {
62
63
  const marketIndexer = await query.indexer.getMarket();
63
- for (const pool of Object.values(marketIndexer.pools)) {
64
- pool.coinPrice = coinPrices[pool.coinName] || pool.coinPrice;
65
- pool.coinWrappedType = query.utils.getCoinWrappedType(pool.coinName);
66
- }
67
- for (const collateral of Object.values(marketIndexer.collaterals)) {
68
- collateral.coinPrice =
69
- coinPrices[collateral.coinName] || collateral.coinPrice;
70
- collateral.coinWrappedType = query.utils.getCoinWrappedType(
71
- collateral.coinName
72
- );
73
- }
64
+
65
+ const updatePools = (item: MarketPool) => {
66
+ item.coinPrice = coinPrices[item.coinName] || item.coinPrice;
67
+ item.coinWrappedType = query.utils.getCoinWrappedType(item.coinName);
68
+ pools[item.coinName] = item;
69
+ };
70
+
71
+ const updateCollaterals = (item: MarketCollateral) => {
72
+ item.coinPrice = coinPrices[item.coinName] || item.coinPrice;
73
+ item.coinWrappedType = query.utils.getCoinWrappedType(item.coinName);
74
+ collaterals[item.coinName] = item;
75
+ };
76
+
77
+ Object.values(marketIndexer.pools).forEach(updatePools);
78
+ Object.values(marketIndexer.collaterals).forEach(updateCollaterals);
79
+
74
80
  return {
75
- pools: marketIndexer.pools,
76
- collaterals: marketIndexer.collaterals,
81
+ pools,
82
+ collaterals,
77
83
  };
78
84
  }
79
85
 
@@ -89,6 +95,7 @@ export const queryMarket = async (
89
95
 
90
96
  for (const pool of marketData?.pools ?? []) {
91
97
  const coinType = normalizeStructTag(pool.type.name);
98
+ if (coinType === NATIVE_USDC) continue;
92
99
  const poolCoinName =
93
100
  query.utils.parseCoinNameFromType<SupportPoolCoins>(coinType);
94
101
  const coinPrice = coinPrices[poolCoinName] ?? 0;
@@ -221,29 +228,31 @@ export const queryMarket = async (
221
228
  */
222
229
  export const getMarketPools = async (
223
230
  query: ScallopQuery,
224
- poolCoinNames?: SupportPoolCoins[],
231
+ poolCoinNames: SupportPoolCoins[] = [...SUPPORT_POOLS],
225
232
  indexer: boolean = false
226
233
  ) => {
227
- poolCoinNames = poolCoinNames || [...SUPPORT_POOLS];
228
234
  const marketId = query.address.get('core.market');
229
235
  const marketObjectResponse = await query.cache.queryGetObject(marketId, {
230
236
  showContent: true,
231
237
  });
232
- const coinPrices = await query.utils.getCoinPrices(poolCoinNames ?? []);
238
+ const coinPrices = (await query.utils.getCoinPrices(poolCoinNames)) ?? {};
233
239
 
234
240
  const marketPools: MarketPools = {};
235
241
 
236
242
  if (indexer) {
237
243
  const marketPoolsIndexer = await query.indexer.getMarketPools();
238
- for (const marketPool of Object.values(marketPoolsIndexer)) {
239
- if (!poolCoinNames.includes(marketPool.coinName)) continue;
244
+
245
+ const updateMarketPool = (marketPool: MarketPool) => {
246
+ if (!poolCoinNames.includes(marketPool.coinName)) return;
240
247
  marketPool.coinPrice =
241
248
  coinPrices[marketPool.coinName] || marketPool.coinPrice;
242
249
  marketPool.coinWrappedType = query.utils.getCoinWrappedType(
243
250
  marketPool.coinName
244
251
  );
245
252
  marketPools[marketPool.coinName] = marketPool;
246
- }
253
+ };
254
+
255
+ Object.values(marketPoolsIndexer).forEach(updateMarketPool);
247
256
 
248
257
  return marketPools;
249
258
  }
@@ -290,6 +299,10 @@ export const getMarketPool = async (
290
299
  let interestModel: InterestModel | undefined;
291
300
  let borrowFeeRate: { value: string } | undefined;
292
301
 
302
+ coinPrice =
303
+ coinPrice ||
304
+ (await query.utils.getCoinPrices([poolCoinName]))?.[poolCoinName];
305
+
293
306
  if (indexer) {
294
307
  const marketPoolIndexer = await query.indexer.getMarketPool(poolCoinName);
295
308
  marketPoolIndexer.coinPrice = coinPrice || marketPoolIndexer.coinPrice;
@@ -309,10 +322,6 @@ export const getMarketPool = async (
309
322
  })
310
323
  )?.data;
311
324
 
312
- coinPrice =
313
- coinPrice ||
314
- (await query.utils.getCoinPrices([poolCoinName]))?.[poolCoinName];
315
-
316
325
  if (marketObject) {
317
326
  if (marketObject.content && 'fields' in marketObject.content) {
318
327
  const fields = marketObject.content.fields as any;
@@ -507,33 +516,32 @@ export const getMarketPool = async (
507
516
  */
508
517
  export const getMarketCollaterals = async (
509
518
  query: ScallopQuery,
510
- collateralCoinNames?: SupportCollateralCoins[],
519
+ collateralCoinNames: SupportCollateralCoins[] = [...SUPPORT_COLLATERALS],
511
520
  indexer: boolean = false
512
521
  ) => {
513
- collateralCoinNames = collateralCoinNames || [...SUPPORT_COLLATERALS];
514
522
  const marketId = query.address.get('core.market');
515
- const [marketObjectResponse, coinPrices] = await Promise.all([
516
- await query.cache.queryGetObject(marketId, {
517
- showContent: true,
518
- }),
519
- await query.utils.getCoinPrices(collateralCoinNames ?? []),
520
- ]);
523
+ const coinPrices =
524
+ (await query.utils.getCoinPrices(collateralCoinNames)) ?? {};
521
525
  const marketCollaterals: MarketCollaterals = {};
522
526
 
523
527
  if (indexer) {
524
528
  const marketCollateralsIndexer = await query.indexer.getMarketCollaterals();
525
- for (const marketCollateral of Object.values(marketCollateralsIndexer)) {
526
- if (!collateralCoinNames.includes(marketCollateral.coinName)) continue;
529
+ const updateMarketCollateral = (marketCollateral: MarketCollateral) => {
530
+ if (!collateralCoinNames.includes(marketCollateral.coinName)) return;
527
531
  marketCollateral.coinPrice =
528
532
  coinPrices[marketCollateral.coinName] || marketCollateral.coinPrice;
529
533
  marketCollateral.coinWrappedType = query.utils.getCoinWrappedType(
530
534
  marketCollateral.coinName
531
535
  );
532
536
  marketCollaterals[marketCollateral.coinName] = marketCollateral;
533
- }
537
+ };
538
+ Object.values(marketCollateralsIndexer).forEach(updateMarketCollateral);
534
539
  return marketCollaterals;
535
540
  }
536
541
 
542
+ const marketObjectResponse = await query.cache.queryGetObject(marketId, {
543
+ showContent: true,
544
+ });
537
545
  await Promise.allSettled(
538
546
  collateralCoinNames.map(async (collateralCoinName) => {
539
547
  const marketCollateral = await getMarketCollateral(
@@ -570,6 +578,12 @@ export const getMarketCollateral = async (
570
578
  marketObject?: SuiObjectData | null,
571
579
  coinPrice?: number
572
580
  ) => {
581
+ coinPrice =
582
+ coinPrice ||
583
+ (await query.utils.getCoinPrices([collateralCoinName]))?.[
584
+ collateralCoinName
585
+ ];
586
+
573
587
  if (indexer) {
574
588
  const marketCollateralIndexer =
575
589
  await query.indexer.getMarketCollateral(collateralCoinName);
@@ -595,12 +609,6 @@ export const getMarketCollateral = async (
595
609
  })
596
610
  )?.data;
597
611
 
598
- coinPrice =
599
- coinPrice ||
600
- (await query.utils.getCoinPrices([collateralCoinName]))?.[
601
- collateralCoinName
602
- ];
603
-
604
612
  if (marketObject) {
605
613
  if (marketObject.content && 'fields' in marketObject.content) {
606
614
  const fields = marketObject.content.fields as any;
@@ -31,10 +31,9 @@ import type {
31
31
  */
32
32
  export const getSpools = async (
33
33
  query: ScallopQuery,
34
- stakeMarketCoinNames?: SupportStakeMarketCoins[],
34
+ stakeMarketCoinNames: SupportStakeMarketCoins[] = [...SUPPORT_SPOOLS],
35
35
  indexer: boolean = false
36
36
  ) => {
37
- stakeMarketCoinNames = stakeMarketCoinNames || [...SUPPORT_SPOOLS];
38
37
  const stakeCoinNames = stakeMarketCoinNames.map((stakeMarketCoinName) =>
39
38
  query.utils.parseCoinName<SupportStakeCoins>(stakeMarketCoinName)
40
39
  );
@@ -43,17 +42,18 @@ export const getSpools = async (
43
42
  query.utils.getSpoolRewardCoinName(stakeMarketCoinName);
44
43
  return rewardCoinName;
45
44
  });
46
- const coinPrices = await query.utils.getCoinPrices(
47
- [...new Set([...stakeCoinNames, ...rewardCoinNames])] ?? []
48
- );
45
+ const coinPrices =
46
+ (await query.utils.getCoinPrices([
47
+ ...new Set([...stakeCoinNames, ...rewardCoinNames]),
48
+ ])) ?? {};
49
49
 
50
50
  const marketPools = await query.getMarketPools(stakeCoinNames, indexer);
51
51
  const spools: Spools = {};
52
52
 
53
53
  if (indexer) {
54
54
  const spoolsIndexer = await query.indexer.getSpools();
55
- for (const spool of Object.values(spoolsIndexer)) {
56
- if (!stakeMarketCoinNames.includes(spool.marketCoinName)) continue;
55
+ const updateSpools = (spool: Spool) => {
56
+ if (!stakeMarketCoinNames.includes(spool.marketCoinName)) return;
57
57
  const coinName = query.utils.parseCoinName<SupportStakeCoins>(
58
58
  spool.marketCoinName
59
59
  );
@@ -68,7 +68,8 @@ export const getSpools = async (
68
68
  spool.rewardCoinPrice =
69
69
  coinPrices[rewardCoinName] || spool.rewardCoinPrice;
70
70
  spools[spool.marketCoinName] = spool;
71
- }
71
+ };
72
+ Object.values(spoolsIndexer).forEach(updateSpools);
72
73
 
73
74
  return spools;
74
75
  }
@@ -116,6 +117,7 @@ export const getSpool = async (
116
117
  `spool.pools.${marketCoinName}.rewardPoolId`
117
118
  );
118
119
  let spool: Spool | undefined = undefined;
120
+ coinPrices = coinPrices || (await query.utils.getCoinPrices([coinName]));
119
121
 
120
122
  if (indexer) {
121
123
  const spoolIndexer = await query.indexer.getSpool(marketCoinName);