@scallop-io/sui-scallop-sdk 1.3.5-rc.1 → 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.
@@ -47,7 +47,6 @@ import {
47
47
  getSCoinAmounts,
48
48
  getSCoinSwapRate,
49
49
  getSCoinTotalSupply,
50
- getAllCoinPrices,
51
50
  } from '../queries';
52
51
  import {
53
52
  ScallopQueryParams,
@@ -192,11 +191,11 @@ export class ScallopQuery {
192
191
  * @param indexer - Whether to use indexer.
193
192
  * @return Market data.
194
193
  */
195
- public async queryMarket(
196
- indexer: boolean = false,
197
- args?: { coinPrices: CoinPrices }
198
- ) {
199
- return await queryMarket(this, indexer, args?.coinPrices);
194
+ public async queryMarket(args?: {
195
+ coinPrices?: CoinPrices;
196
+ indexer?: boolean;
197
+ }) {
198
+ return await queryMarket(this, args?.indexer, args?.coinPrices);
200
199
  }
201
200
 
202
201
  /**
@@ -212,12 +211,17 @@ export class ScallopQuery {
212
211
  */
213
212
  public async getMarketPools(
214
213
  poolCoinNames?: SupportPoolCoins[],
215
- indexer: boolean = false,
216
214
  args?: {
217
215
  coinPrices?: CoinPrices;
216
+ indexer?: boolean;
218
217
  }
219
218
  ) {
220
- return await getMarketPools(this, poolCoinNames, indexer, args?.coinPrices);
219
+ return await getMarketPools(
220
+ this,
221
+ poolCoinNames,
222
+ args?.indexer,
223
+ args?.coinPrices
224
+ );
221
225
  }
222
226
 
223
227
  /**
@@ -229,16 +233,16 @@ export class ScallopQuery {
229
233
  */
230
234
  public async getMarketPool(
231
235
  poolCoinName: SupportPoolCoins,
232
- indexer: boolean = false,
233
236
  args?: {
234
237
  marketObject?: SuiObjectData | null;
235
238
  coinPrice?: number;
239
+ indexer?: boolean;
236
240
  }
237
241
  ) {
238
242
  return await getMarketPool(
239
243
  this,
240
244
  poolCoinName,
241
- indexer,
245
+ args?.indexer,
242
246
  args?.marketObject,
243
247
  args?.coinPrice
244
248
  );
@@ -257,9 +261,9 @@ export class ScallopQuery {
257
261
  */
258
262
  public async getMarketCollaterals(
259
263
  collateralCoinNames?: SupportCollateralCoins[],
260
- indexer: boolean = false
264
+ args?: { indexer?: boolean }
261
265
  ) {
262
- return await getMarketCollaterals(this, collateralCoinNames, indexer);
266
+ return await getMarketCollaterals(this, collateralCoinNames, args?.indexer);
263
267
  }
264
268
 
265
269
  /**
@@ -271,9 +275,9 @@ export class ScallopQuery {
271
275
  */
272
276
  public async getMarketCollateral(
273
277
  collateralCoinName: SupportCollateralCoins,
274
- indexer: boolean = false
278
+ args?: { indexer?: boolean }
275
279
  ) {
276
- return await getMarketCollateral(this, collateralCoinName, indexer);
280
+ return await getMarketCollateral(this, collateralCoinName, args?.indexer);
277
281
  }
278
282
 
279
283
  /**
@@ -383,16 +387,16 @@ export class ScallopQuery {
383
387
  */
384
388
  public async getSpools(
385
389
  stakeMarketCoinNames?: SupportStakeMarketCoins[],
386
- indexer: boolean = false,
387
390
  args?: {
388
391
  marketPools?: MarketPools;
389
392
  coinPrices?: CoinPrices;
393
+ indexer?: boolean;
390
394
  }
391
395
  ) {
392
396
  return await getSpools(
393
397
  this,
394
398
  stakeMarketCoinNames,
395
- indexer,
399
+ args?.indexer,
396
400
  args?.marketPools,
397
401
  args?.coinPrices
398
402
  );
@@ -407,13 +411,16 @@ export class ScallopQuery {
407
411
  */
408
412
  public async getSpool(
409
413
  stakeMarketCoinName: SupportStakeMarketCoins,
410
- indexer: boolean = false,
411
- args?: { marketPool?: MarketPool; coinPrices?: CoinPrices }
414
+ args?: {
415
+ marketPool?: MarketPool;
416
+ coinPrices?: CoinPrices;
417
+ indexer?: boolean;
418
+ }
412
419
  ) {
413
420
  return await getSpool(
414
421
  this,
415
422
  stakeMarketCoinName,
416
- indexer,
423
+ args?.indexer,
417
424
  args?.marketPool,
418
425
  args?.coinPrices
419
426
  );
@@ -537,14 +544,12 @@ export class ScallopQuery {
537
544
  */
538
545
  public async getBorrowIncentivePools(
539
546
  coinNames?: SupportBorrowIncentiveCoins[],
540
- indexer: boolean = false,
541
- args?: { marketPools?: MarketPools; coinPrices?: CoinPrices }
547
+ args?: { coinPrices: CoinPrices; indexer?: boolean }
542
548
  ) {
543
549
  return await getBorrowIncentivePools(
544
550
  this,
545
551
  coinNames,
546
- indexer,
547
- args?.marketPools,
552
+ args?.indexer,
548
553
  args?.coinPrices
549
554
  );
550
555
  }
@@ -574,9 +579,9 @@ export class ScallopQuery {
574
579
  public async getLendings(
575
580
  poolCoinNames?: SupportPoolCoins[],
576
581
  ownerAddress: string = this.walletAddress,
577
- indexer: boolean = false
582
+ args?: { indexer?: boolean }
578
583
  ) {
579
- return await getLendings(this, poolCoinNames, ownerAddress, indexer);
584
+ return await getLendings(this, poolCoinNames, ownerAddress, args?.indexer);
580
585
  }
581
586
 
582
587
  /**
@@ -590,9 +595,9 @@ export class ScallopQuery {
590
595
  public async getLending(
591
596
  poolCoinName: SupportPoolCoins,
592
597
  ownerAddress: string = this.walletAddress,
593
- indexer: boolean = false
598
+ args?: { indexer?: boolean }
594
599
  ) {
595
- return await getLending(this, poolCoinName, ownerAddress, indexer);
600
+ return await getLending(this, poolCoinName, ownerAddress, args?.indexer);
596
601
  }
597
602
 
598
603
  /**
@@ -607,9 +612,9 @@ export class ScallopQuery {
607
612
  */
608
613
  public async getObligationAccounts(
609
614
  ownerAddress: string = this.walletAddress,
610
- indexer: boolean = false
615
+ args?: { indexer: boolean }
611
616
  ) {
612
- return await getObligationAccounts(this, ownerAddress, indexer);
617
+ return await getObligationAccounts(this, ownerAddress, args?.indexer);
613
618
  }
614
619
 
615
620
  /**
@@ -626,13 +631,13 @@ export class ScallopQuery {
626
631
  public async getObligationAccount(
627
632
  obligationId: string,
628
633
  ownerAddress: string = this.walletAddress,
629
- indexer: boolean = false
634
+ args?: { indexer?: boolean }
630
635
  ) {
631
636
  return await getObligationAccount(
632
637
  this,
633
638
  obligationId,
634
639
  ownerAddress,
635
- indexer
640
+ args?.indexer
636
641
  );
637
642
  }
638
643
 
@@ -645,8 +650,8 @@ export class ScallopQuery {
645
650
  *
646
651
  * @return Total value locked.
647
652
  */
648
- public async getTvl(indexer: boolean = false) {
649
- return await getTotalValueLocked(this, indexer);
653
+ public async getTvl(args?: { indexer?: boolean }) {
654
+ return await getTotalValueLocked(this, args?.indexer);
650
655
  }
651
656
 
652
657
  /**
@@ -819,15 +824,4 @@ export class ScallopQuery {
819
824
  public async getCoinPriceByIndexer(poolName: SupportPoolCoins) {
820
825
  return this.indexer.getCoinPrice(poolName);
821
826
  }
822
-
823
- /**
824
- * Get all coin prices, including sCoin
825
- * @returns prices data
826
- */
827
- public async getAllCoinPrices(args?: {
828
- marketPools?: MarketPools;
829
- coinPrices?: CoinPrices;
830
- }) {
831
- return getAllCoinPrices(this, args?.marketPools, args?.coinPrices);
832
- }
833
827
  }
@@ -8,6 +8,7 @@ import {
8
8
  SUPPORT_POOLS,
9
9
  SUPPORT_COLLATERALS,
10
10
  spoolRewardCoins,
11
+ borrowIncentiveRewardCoins,
11
12
  coinDecimals,
12
13
  wormholeCoinIds,
13
14
  voloCoinIds,
@@ -20,7 +21,6 @@ import {
20
21
  COIN_GECKGO_IDS,
21
22
  POOL_ADDRESSES,
22
23
  sCoinTypeToName,
23
- sCoinRawNameToName,
24
24
  } from '../constants';
25
25
  import { getPythPrices, queryObligation } from '../queries';
26
26
  import {
@@ -40,6 +40,7 @@ import type {
40
40
  SupportAssetCoins,
41
41
  SupportMarketCoins,
42
42
  SupportStakeMarketCoins,
43
+ SupportBorrowIncentiveCoins,
43
44
  CoinPrices,
44
45
  CoinWrappedType,
45
46
  SupportSCoin,
@@ -156,14 +157,7 @@ export class ScallopUtils {
156
157
  * @param coinName - Specific support coin name.
157
158
  * @return Coin type.
158
159
  */
159
- public parseCoinType(
160
- coinName: SupportCoins,
161
- useOldMarketCoin: boolean = false
162
- ) {
163
- // try parse scoin first
164
- if (sCoinIds[coinName as SupportSCoin] && !useOldMarketCoin) {
165
- return sCoinIds[coinName as SupportSCoin];
166
- }
160
+ public parseCoinType(coinName: SupportCoins) {
167
161
  coinName = isMarketCoin(coinName) ? this.parseCoinName(coinName) : coinName;
168
162
  const coinPackageId =
169
163
  this.address.get(`core.coins.${coinName}.id`) ||
@@ -231,16 +225,6 @@ export class ScallopUtils {
231
225
  }
232
226
  }
233
227
 
234
- /**
235
- * Convert sCoin name to coin name.
236
- * This function will parse new sCoin name `scallop_...` to its old market coin name which is shorter
237
- * e.g: `scallop_sui -> ssui
238
- * @return sCoin name
239
- */
240
- public parseCoinNameFromSCoinName(coinName: string) {
241
- return sCoinRawNameToName[coinName];
242
- }
243
-
244
228
  /**
245
229
  * Convert sCoin name into sCoin type
246
230
  * @param sCoinName
@@ -288,7 +272,7 @@ export class ScallopUtils {
288
272
  public parseMarketCoinType(coinName: SupportCoins) {
289
273
  const protocolObjectId =
290
274
  this.address.get('core.object') ?? PROTOCOL_OBJECT_ID;
291
- const coinType = this.parseCoinType(coinName, true);
275
+ const coinType = this.parseCoinType(coinName);
292
276
  return `${protocolObjectId}::reserve::MarketCoin<${coinType}>`;
293
277
  }
294
278
 
@@ -313,13 +297,12 @@ export class ScallopUtils {
313
297
  ): T extends SupportCoins ? T : SupportCoins;
314
298
  public parseCoinNameFromType(coinType: string) {
315
299
  coinType = normalizeStructTag(coinType);
316
-
317
300
  const coinTypeRegex = new RegExp(`((0x[^:]+::[^:]+::[^<>]+))(?![^<>]*<)`);
318
301
  const coinTypeMatch = coinType.match(coinTypeRegex);
319
302
  const isMarketCoinType = coinType.includes('reserve::MarketCoin');
320
303
  coinType = coinTypeMatch?.[1] ?? coinType;
321
304
 
322
- const wormholeCoinTypeMap: Record<string, SupportAssetCoins> = {
305
+ const wormHoleCoinTypeMap: Record<string, SupportAssetCoins> = {
323
306
  [`${
324
307
  this.address.get('core.coins.wusdc.id') ?? wormholeCoinIds.wusdc
325
308
  }::coin::COIN`]: 'wusdc',
@@ -356,7 +339,7 @@ export class ScallopUtils {
356
339
  );
357
340
 
358
341
  const assetCoinName =
359
- wormholeCoinTypeMap[coinType] ||
342
+ wormHoleCoinTypeMap[coinType] ||
360
343
  voloCoinTypeMap[coinType] ||
361
344
  suiBridgeTypeMap[coinType] ||
362
345
  (coinType.split('::')[2].toLowerCase() as SupportAssetCoins);
@@ -400,6 +383,18 @@ export class ScallopUtils {
400
383
  return spoolRewardCoins[stakeMarketCoinName];
401
384
  };
402
385
 
386
+ /**
387
+ * Get reward type of borrow incentive pool.
388
+ *
389
+ * @param borrowIncentiveCoinName - Support borrow incentive coin.
390
+ * @return Borrow incentive reward coin name.
391
+ */
392
+ public getBorrowIncentiveRewardCoinName = (
393
+ borrowIncentiveCoinName: SupportBorrowIncentiveCoins
394
+ ) => {
395
+ return borrowIncentiveRewardCoins[borrowIncentiveCoinName];
396
+ };
397
+
403
398
  /**
404
399
  * Get coin decimal.
405
400
  *
@@ -1,9 +1,5 @@
1
1
  import { normalizeStructTag } from '@mysten/sui/utils';
2
- import {
3
- sCoinRawNameToName,
4
- SUPPORT_BORROW_INCENTIVE_POOLS,
5
- SUPPORT_BORROW_INCENTIVE_REWARDS,
6
- } from '../constants';
2
+ import { SUPPORT_BORROW_INCENTIVE_POOLS } from '../constants';
7
3
  import {
8
4
  parseOriginBorrowIncentivePoolData,
9
5
  parseOriginBorrowIncentiveAccountData,
@@ -21,7 +17,6 @@ import type {
21
17
  OptionalKeys,
22
18
  BorrowIncentivePool,
23
19
  CoinPrices,
24
- MarketPools,
25
20
  } from '../types';
26
21
  import BigNumber from 'bignumber.js';
27
22
 
@@ -60,14 +55,11 @@ export const getBorrowIncentivePools = async (
60
55
  ...SUPPORT_BORROW_INCENTIVE_POOLS,
61
56
  ],
62
57
  indexer: boolean = false,
63
- marketPools?: MarketPools,
64
58
  coinPrices?: CoinPrices
65
59
  ) => {
66
60
  const borrowIncentivePools: BorrowIncentivePools = {};
67
- marketPools =
68
- marketPools ??
69
- (await query.getMarketPools(undefined, false, { coinPrices }));
70
- coinPrices = coinPrices ?? (await query.getAllCoinPrices({ marketPools }));
61
+
62
+ coinPrices = coinPrices ?? (await query.utils.getCoinPrices()) ?? {};
71
63
 
72
64
  if (indexer) {
73
65
  const borrowIncentivePoolsIndexer =
@@ -75,13 +67,7 @@ export const getBorrowIncentivePools = async (
75
67
 
76
68
  const updateBorrowIncentivePool = (pool: BorrowIncentivePool) => {
77
69
  if (!borrowIncentiveCoinNames.includes(pool.coinName)) return;
78
- pool.coinPrice = coinPrices[pool.coinName] || pool.coinPrice;
79
- for (const sCoinName of SUPPORT_BORROW_INCENTIVE_REWARDS) {
80
- if (pool.points[sCoinName]) {
81
- pool.points[sCoinName].coinPrice =
82
- coinPrices[sCoinName] ?? pool.points[sCoinName].coinPrice;
83
- }
84
- }
70
+ pool.coinPrice = coinPrices[pool.coinName] ?? pool.coinPrice;
85
71
  borrowIncentivePools[pool.coinName] = pool;
86
72
  };
87
73
 
@@ -108,6 +94,7 @@ export const getBorrowIncentivePools = async (
108
94
  query.utils.parseCoinNameFromType<SupportBorrowIncentiveCoins>(
109
95
  poolCoinType
110
96
  );
97
+
111
98
  const poolCoinPrice = coinPrices?.[poolCoinName] ?? 0;
112
99
  const poolCoinDecimal = query.utils.getCoinDecimal(poolCoinName);
113
100
 
@@ -115,21 +102,17 @@ export const getBorrowIncentivePools = async (
115
102
  if (!borrowIncentiveCoinNames.includes(poolCoinName)) {
116
103
  continue;
117
104
  }
118
-
119
- // pool points for borrow incentive reward
105
+ // pool points for borrow incentive reward ('sui' and 'sca')
120
106
  for (const [coinName, poolPoint] of Object.entries(
121
107
  parsedBorrowIncentivePoolData.poolPoints
122
108
  )) {
123
- const rewardCoinType = poolPoint.pointType;
124
- let rewardCoinName = query.utils.parseCoinNameFromType(
125
- rewardCoinType
126
- ) as SupportBorrowIncentiveRewardCoins;
127
- // handle for scoin name
128
- if (sCoinRawNameToName[rewardCoinName]) {
129
- rewardCoinName = sCoinRawNameToName[rewardCoinName];
130
- }
131
- const rewardCoinDecimal = query.utils.getCoinDecimal(rewardCoinName);
109
+ const rewardCoinType = normalizeStructTag(poolPoint.pointType);
110
+ const rewardCoinName =
111
+ query.utils.parseCoinNameFromType<SupportBorrowIncentiveRewardCoins>(
112
+ rewardCoinType
113
+ );
132
114
  const rewardCoinPrice = coinPrices?.[rewardCoinName] ?? 0;
115
+ const rewardCoinDecimal = query.utils.getCoinDecimal(rewardCoinName);
133
116
 
134
117
  const symbol = query.utils.parseSymbol(rewardCoinName);
135
118
  const coinDecimal = query.utils.getCoinDecimal(rewardCoinName);