@scallop-io/sui-scallop-sdk 1.3.5-alpha.1 → 1.3.5-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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scallop-io/sui-scallop-sdk",
3
- "version": "1.3.5-alpha.1",
3
+ "version": "1.3.5-alpha.2",
4
4
  "description": "Typescript sdk for interacting with Scallop contract on SUI",
5
5
  "keywords": [
6
6
  "sui",
@@ -69,7 +69,6 @@ export const getBorrowIncentivePools = async (
69
69
  (await query.getMarketPools(undefined, false, { coinPrices }));
70
70
  coinPrices = coinPrices ?? (await query.getAllCoinPrices({ marketPools }));
71
71
 
72
- console.log({ coinPrices });
73
72
  if (indexer) {
74
73
  const borrowIncentivePoolsIndexer =
75
74
  await query.indexer.getBorrowIncentivePools();
@@ -1,6 +1,5 @@
1
1
  import BigNumber from 'bignumber.js';
2
2
  import {
3
- SUPPORT_BORROW_INCENTIVE_REWARDS,
4
3
  SUPPORT_COLLATERALS,
5
4
  SUPPORT_POOLS,
6
5
  SUPPORT_SPOOLS,
@@ -353,8 +352,9 @@ export const getObligationAccount = async (
353
352
  const collateralAssetCoinNames: SupportCollateralCoins[] = [
354
353
  ...SUPPORT_COLLATERALS,
355
354
  ];
356
- coinPrices = coinPrices ?? (await query.utils.getCoinPrices());
357
- market = market ?? (await query.queryMarket(indexer, { coinPrices }));
355
+ market = market ?? (await query.queryMarket(indexer));
356
+ coinPrices =
357
+ coinPrices ?? (await query.getAllCoinPrices({ marketPools: market.pools }));
358
358
  coinAmounts =
359
359
  coinAmounts ||
360
360
  (await query.getCoinAmounts(collateralAssetCoinNames, ownerAddress));
@@ -522,64 +522,70 @@ export const getObligationAccount = async (
522
522
  const borrowIncentivePool = borrowIncentivePools[coinName];
523
523
  if (borrowIncentivePool) {
524
524
  const rewards: ObligationBorrowIcentiveReward[] = [];
525
- for (const rewardCoinName of SUPPORT_BORROW_INCENTIVE_REWARDS) {
526
- const accountPoint = borrowIncentiveAccount.pointList[rewardCoinName];
527
- const poolPoint = borrowIncentivePool.points[rewardCoinName];
528
-
529
- if (accountPoint && poolPoint) {
530
- let availableClaimAmount = BigNumber(0);
531
- let availableClaimCoin = BigNumber(0);
532
- const accountBorrowedAmount = BigNumber(accountPoint.weightedAmount);
533
- const baseIndexRate = 1_000_000_000;
534
- const increasedPointRate = poolPoint.currentPointIndex
535
- ? Math.max(
536
- BigNumber(poolPoint.currentPointIndex - accountPoint.index)
537
- .dividedBy(baseIndexRate)
538
- .toNumber(),
539
- 0
540
- )
541
- : 1;
542
- availableClaimAmount = availableClaimAmount.plus(
543
- accountBorrowedAmount
544
- .multipliedBy(increasedPointRate)
545
- .plus(accountPoint.points)
546
- );
547
- availableClaimCoin = availableClaimAmount.shiftedBy(
548
- -1 * poolPoint.coinDecimal
549
- );
550
-
551
- // for veSCA
552
- const weightScale = BigNumber(1_000_000_000_000);
553
- const boostValue = BigNumber(accountPoint.weightedAmount)
554
- .div(
555
- BigNumber(borrowIncentiveAccount.debtAmount)
556
- .multipliedBy(poolPoint.baseWeight)
557
- .dividedBy(weightScale)
558
- )
559
- .isFinite()
560
- ? BigNumber(accountPoint.weightedAmount)
561
- .div(
562
- BigNumber(borrowIncentiveAccount.debtAmount)
563
- .multipliedBy(poolPoint.baseWeight)
564
- .dividedBy(weightScale)
525
+ Object.entries(borrowIncentiveAccount.pointList).forEach(
526
+ ([key, accountPoint]) => {
527
+ const poolPoint =
528
+ borrowIncentivePool.points[
529
+ key as SupportBorrowIncentiveRewardCoins
530
+ ];
531
+
532
+ if (accountPoint && poolPoint) {
533
+ let availableClaimAmount = BigNumber(0);
534
+ let availableClaimCoin = BigNumber(0);
535
+ const accountBorrowedAmount = BigNumber(
536
+ accountPoint.weightedAmount
537
+ );
538
+ const baseIndexRate = 1_000_000_000;
539
+ const increasedPointRate = poolPoint.currentPointIndex
540
+ ? Math.max(
541
+ BigNumber(poolPoint.currentPointIndex - accountPoint.index)
542
+ .dividedBy(baseIndexRate)
543
+ .toNumber(),
544
+ 0
565
545
  )
566
- .toNumber()
567
- : 1;
568
-
569
- if (availableClaimAmount.isGreaterThanOrEqualTo(0)) {
570
- rewards.push({
571
- coinName: poolPoint.coinName,
572
- coinType: poolPoint.coinType,
573
- symbol: poolPoint.symbol,
574
- coinDecimal: poolPoint.coinDecimal,
575
- coinPrice: poolPoint.coinPrice,
576
- availableClaimAmount: availableClaimAmount.toNumber(),
577
- availableClaimCoin: availableClaimCoin.toNumber(),
578
- boostValue,
579
- });
546
+ : 1;
547
+ availableClaimAmount = availableClaimAmount.plus(
548
+ accountBorrowedAmount
549
+ .multipliedBy(increasedPointRate)
550
+ .plus(accountPoint.points)
551
+ );
552
+ availableClaimCoin = availableClaimAmount.shiftedBy(
553
+ -1 * poolPoint.coinDecimal
554
+ );
555
+
556
+ // for veSCA
557
+ const weightScale = BigNumber(1_000_000_000_000);
558
+ const boostValue = BigNumber(accountPoint.weightedAmount)
559
+ .div(
560
+ BigNumber(borrowIncentiveAccount.debtAmount)
561
+ .multipliedBy(poolPoint.baseWeight)
562
+ .dividedBy(weightScale)
563
+ )
564
+ .isFinite()
565
+ ? BigNumber(accountPoint.weightedAmount)
566
+ .div(
567
+ BigNumber(borrowIncentiveAccount.debtAmount)
568
+ .multipliedBy(poolPoint.baseWeight)
569
+ .dividedBy(weightScale)
570
+ )
571
+ .toNumber()
572
+ : 1;
573
+
574
+ if (availableClaimAmount.isGreaterThanOrEqualTo(0)) {
575
+ rewards.push({
576
+ coinName: poolPoint.coinName,
577
+ coinType: poolPoint.coinType,
578
+ symbol: poolPoint.symbol,
579
+ coinDecimal: poolPoint.coinDecimal,
580
+ coinPrice: poolPoint.coinPrice,
581
+ availableClaimAmount: availableClaimAmount.toNumber(),
582
+ availableClaimCoin: availableClaimCoin.toNumber(),
583
+ boostValue,
584
+ });
585
+ }
580
586
  }
581
587
  }
582
- }
588
+ );
583
589
 
584
590
  if (
585
591
  Object.keys(borrowIncentivePool.points).some((coinName: any) => {