@scallop-io/sui-scallop-sdk 0.44.5 → 0.44.7

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.
@@ -192,7 +192,7 @@ export declare class ScallopClient {
192
192
  * @param walletAddress - The wallet address of the owner.
193
193
  * @return Transaction block response or transaction block.
194
194
  */
195
- repay<S extends boolean>(poolCoinName: SupportPoolCoins, amount: number, sign: S | undefined, obligationId: string, walletAddress?: string): Promise<ScallopClientFnReturnType<S>>;
195
+ repay<S extends boolean>(poolCoinName: SupportPoolCoins, amount: number, sign: S | undefined, obligationId: string, obligationKey: string, walletAddress?: string): Promise<ScallopClientFnReturnType<S>>;
196
196
  /**
197
197
  * FlashLoan asset from the specific pool.
198
198
  *
@@ -262,6 +262,7 @@ export declare class ScallopQuery {
262
262
  */
263
263
  getBorrowIncentivePools(coinNames?: SupportBorrowIncentiveCoins[]): Promise<{
264
264
  usdc?: import("../types").BorrowIncentivePool | undefined;
265
+ usdt?: import("../types").BorrowIncentivePool | undefined;
265
266
  sui?: import("../types").BorrowIncentivePool | undefined;
266
267
  }>;
267
268
  /**
@@ -273,6 +274,7 @@ export declare class ScallopQuery {
273
274
  */
274
275
  getBorrowIncentiveAccounts(obligationId: string, coinNames?: SupportBorrowIncentiveCoins[]): Promise<{
275
276
  usdc?: import("../types").ParsedBorrowIncentiveAccountData | undefined;
277
+ usdt?: import("../types").ParsedBorrowIncentiveAccountData | undefined;
276
278
  sui?: import("../types").ParsedBorrowIncentiveAccountData | undefined;
277
279
  }>;
278
280
  /**
@@ -322,9 +324,10 @@ export declare class ScallopQuery {
322
324
  * borrowing and obligation information for specific pool.
323
325
  *
324
326
  * @param obligationId - The obligation id.
327
+ * @param ownerAddress - The owner address.
325
328
  * @return Borrowing and collateral information.
326
329
  */
327
- getObligationAccount(obligationId: string): Promise<import("../types").ObligationAccount>;
330
+ getObligationAccount(obligationId: string, ownerAddress?: string): Promise<import("../types").ObligationAccount>;
328
331
  /**
329
332
  * Get total value locked.
330
333
  *
@@ -9,6 +9,7 @@ import type { SupportBorrowIncentiveCoins } from '../types';
9
9
  */
10
10
  export declare const queryBorrowIncentivePools: (query: ScallopQuery, borrowIncentiveCoinNames?: SupportBorrowIncentiveCoins[]) => Promise<{
11
11
  usdc?: import("../types").BorrowIncentivePool | undefined;
12
+ usdt?: import("../types").BorrowIncentivePool | undefined;
12
13
  sui?: import("../types").BorrowIncentivePool | undefined;
13
14
  }>;
14
15
  /**
@@ -20,5 +21,6 @@ export declare const queryBorrowIncentivePools: (query: ScallopQuery, borrowInce
20
21
  */
21
22
  export declare const queryBorrowIncentiveAccounts: (query: ScallopQuery, obligationId: string, borrowIncentiveCoinNames?: SupportBorrowIncentiveCoins[]) => Promise<{
22
23
  usdc?: import("../types").ParsedBorrowIncentiveAccountData | undefined;
24
+ usdt?: import("../types").ParsedBorrowIncentiveAccountData | undefined;
23
25
  sui?: import("../types").ParsedBorrowIncentiveAccountData | undefined;
24
26
  }>;
@@ -77,6 +77,8 @@ export type ObligationDebt = {
77
77
  borrowedValue: number;
78
78
  borrowedValueWithWeight: number;
79
79
  borrowIndex: number;
80
+ requiredRepayAmount: number;
81
+ requiredRepayCoin: number;
80
82
  availableBorrowAmount: number;
81
83
  availableBorrowCoin: number;
82
84
  availableRepayAmount: number;
@@ -58,3 +58,11 @@ export declare const calculateBorrowIncentiveRewardPoolData: (parsedBorrowIncent
58
58
  export declare const parseOriginBorrowIncentiveAccountData: (originBorrowIncentiveAccountData: OriginBorrowIncentiveAccountData) => ParsedBorrowIncentiveAccountData;
59
59
  export declare const minBigNumber: (...args: BigNumber.Value[]) => BigNumber;
60
60
  export declare const maxBigNumber: (...args: BigNumber.Value[]) => BigNumber;
61
+ /**
62
+ * Dynamically adjust the decrease or increase ratio according to the amout
63
+ * @param amount - The amount required to calculate factor.
64
+ * @param scaleStep - The scale step required to determine the factor..
65
+ * @param type - The type of the calculation.
66
+ * @return The estimated factor
67
+ * */
68
+ export declare const estimatedFactor: (amount: number, scaleStep: number, type: 'increase' | 'decrease') => number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scallop-io/sui-scallop-sdk",
3
- "version": "0.44.5",
3
+ "version": "0.44.7",
4
4
  "description": "Typescript sdk for interacting with Scallop contract on SUI",
5
5
  "keywords": [
6
6
  "sui",
@@ -40,7 +40,7 @@ export const SUPPORT_SPOOLS = ['ssui', 'susdc', 'susdt'] as const;
40
40
 
41
41
  export const SUPPORT_SPOOLS_REWARDS = ['sui'] as const;
42
42
 
43
- export const SUPPORT_BORROW_INCENTIVE_POOLS = ['sui', 'usdc'] as const;
43
+ export const SUPPORT_BORROW_INCENTIVE_POOLS = ['sui', 'usdc', 'usdt'] as const;
44
44
 
45
45
  export const SUPPORT_BORROW_INCENTIVE_REWARDS = ['sui'] as const;
46
46
  export const SUPPORT_ORACLES = ['supra', 'switchboard', 'pyth'] as const;
@@ -78,6 +78,7 @@ export const spoolRewardCoins: StakeRewardCoins = {
78
78
  export const borrowIncentiveRewardCoins: BorrowIncentiveRewardCoins = {
79
79
  sui: 'sui',
80
80
  usdc: 'sui',
81
+ usdt: 'sui',
81
82
  };
82
83
 
83
84
  export const coinIds: AssetCoinIds = {
@@ -1,6 +1,6 @@
1
1
  import { normalizeSuiAddress } from '@mysten/sui.js/utils';
2
2
  import { SuiKit } from '@scallop-io/sui-kit';
3
- import { ADDRESSES_ID } from '../constants';
3
+ import { ADDRESSES_ID, SUPPORT_BORROW_INCENTIVE_POOLS } from '../constants';
4
4
  import { ScallopAddress } from './scallopAddress';
5
5
  import { ScallopUtils } from './scallopUtils';
6
6
  import { ScallopBuilder } from './scallopBuilder';
@@ -481,6 +481,16 @@ export class ScallopClient {
481
481
  const sender = walletAddress || this.walletAddress;
482
482
  txBlock.setSender(sender);
483
483
 
484
+ const availableStake = (
485
+ SUPPORT_BORROW_INCENTIVE_POOLS as readonly SupportPoolCoins[]
486
+ ).includes(poolCoinName);
487
+ if (sign && availableStake) {
488
+ await txBlock.unstakeObligationQuick(
489
+ poolCoinName as SupportBorrowIncentiveCoins,
490
+ obligationId,
491
+ obligationKey
492
+ );
493
+ }
484
494
  const coin = await txBlock.borrowQuick(
485
495
  amount,
486
496
  poolCoinName,
@@ -488,6 +498,13 @@ export class ScallopClient {
488
498
  obligationKey
489
499
  );
490
500
  txBlock.transferObjects([coin], sender);
501
+ if (sign && availableStake) {
502
+ await txBlock.stakeObligationQuick(
503
+ poolCoinName as SupportBorrowIncentiveCoins,
504
+ obligationId,
505
+ obligationKey
506
+ );
507
+ }
491
508
 
492
509
  if (sign) {
493
510
  return (await this.suiKit.signAndSendTxn(
@@ -513,13 +530,31 @@ export class ScallopClient {
513
530
  amount: number,
514
531
  sign: S = true as S,
515
532
  obligationId: string,
533
+ obligationKey: string,
516
534
  walletAddress?: string
517
535
  ): Promise<ScallopClientFnReturnType<S>> {
518
536
  const txBlock = this.builder.createTxBlock();
519
537
  const sender = walletAddress || this.walletAddress;
520
538
  txBlock.setSender(sender);
521
539
 
540
+ const availableStake = (
541
+ SUPPORT_BORROW_INCENTIVE_POOLS as readonly SupportPoolCoins[]
542
+ ).includes(poolCoinName);
543
+ if (sign && availableStake) {
544
+ await txBlock.unstakeObligationQuick(
545
+ poolCoinName as SupportBorrowIncentiveCoins,
546
+ obligationId,
547
+ obligationKey
548
+ );
549
+ }
522
550
  await txBlock.repayQuick(amount, poolCoinName, obligationId);
551
+ if (sign && availableStake) {
552
+ await txBlock.stakeObligationQuick(
553
+ poolCoinName as SupportBorrowIncentiveCoins,
554
+ obligationId,
555
+ obligationKey
556
+ );
557
+ }
523
558
 
524
559
  if (sign) {
525
560
  return (await this.suiKit.signAndSendTxn(
@@ -444,10 +444,14 @@ export class ScallopQuery {
444
444
  * borrowing and obligation information for specific pool.
445
445
  *
446
446
  * @param obligationId - The obligation id.
447
+ * @param ownerAddress - The owner address.
447
448
  * @return Borrowing and collateral information.
448
449
  */
449
- public async getObligationAccount(obligationId: string) {
450
- return await getObligationAccount(this, obligationId);
450
+ public async getObligationAccount(
451
+ obligationId: string,
452
+ ownerAddress?: string
453
+ ) {
454
+ return await getObligationAccount(this, obligationId, ownerAddress);
451
455
  }
452
456
 
453
457
  /**
@@ -1,6 +1,6 @@
1
1
  import BigNumber from 'bignumber.js';
2
2
  import { SUPPORT_POOLS, SUPPORT_SPOOLS } from '../constants';
3
- import { minBigNumber } from 'src/utils';
3
+ import { minBigNumber, estimatedFactor } from 'src/utils';
4
4
  import type { ScallopQuery } from '../models';
5
5
  import type {
6
6
  Market,
@@ -321,18 +321,22 @@ export const getObligationAccount = async (
321
321
  let totalBorrowedValue = BigNumber(0);
322
322
  let totalBorrowedValueWithWeight = BigNumber(0);
323
323
 
324
- for (const collateral of obligationQuery.collaterals) {
325
- const collateralCoinName =
326
- query.utils.parseCoinNameFromType<SupportCollateralCoins>(
327
- collateral.type.name
328
- );
329
- const coinDecimal = query.utils.getCoinDecimal(collateralCoinName);
330
- const marketCollateral = market.collaterals[collateralCoinName];
331
- const coinPrice = coinPrices?.[collateralCoinName];
332
- const coinAmount = coinAmounts?.[collateralCoinName] ?? 0;
324
+ for (const assetCoinName of assetCoinNames) {
325
+ const collateral = obligationQuery.collaterals.find((collateral) => {
326
+ const collateralCoinName =
327
+ query.utils.parseCoinNameFromType<SupportCollateralCoins>(
328
+ collateral.type.name
329
+ );
330
+ return assetCoinName === collateralCoinName;
331
+ });
332
+
333
+ const marketCollateral = market.collaterals[assetCoinName];
334
+ const coinDecimal = query.utils.getCoinDecimal(assetCoinName);
335
+ const coinPrice = coinPrices?.[assetCoinName];
336
+ const coinAmount = coinAmounts?.[assetCoinName] ?? 0;
333
337
 
334
338
  if (marketCollateral && coinPrice) {
335
- const depositedAmount = BigNumber(collateral.amount);
339
+ const depositedAmount = BigNumber(collateral?.amount ?? 0);
336
340
  const depositedCoin = depositedAmount.shiftedBy(-1 * coinDecimal);
337
341
  const depositedValue = depositedCoin.multipliedBy(coinPrice);
338
342
  const borrowCapacityValue = depositedValue.multipliedBy(
@@ -357,10 +361,10 @@ export const getObligationAccount = async (
357
361
  totalDepositedPools++;
358
362
  }
359
363
 
360
- collaterals[collateralCoinName] = {
361
- coinName: collateralCoinName,
362
- coinType: collateral.type.name,
363
- symbol: query.utils.parseSymbol(collateralCoinName),
364
+ collaterals[assetCoinName] = {
365
+ coinName: assetCoinName,
366
+ coinType: query.utils.parseCoinType(assetCoinName),
367
+ symbol: query.utils.parseSymbol(assetCoinName),
364
368
  coinDecimal: coinDecimal,
365
369
  coinPrice: coinPrice,
366
370
  depositedAmount: depositedAmount.toNumber(),
@@ -376,26 +380,37 @@ export const getObligationAccount = async (
376
380
  }
377
381
  }
378
382
 
379
- for (const debt of obligationQuery.debts) {
380
- const poolCoinName = query.utils.parseCoinNameFromType<SupportPoolCoins>(
381
- debt.type.name
382
- );
383
- const coinDecimal = query.utils.getCoinDecimal(poolCoinName);
384
- const marketPool = market.pools[poolCoinName];
385
- const coinPrice = coinPrices?.[poolCoinName];
383
+ for (const assetCoinName of assetCoinNames) {
384
+ const debt = obligationQuery.debts.find((debt) => {
385
+ const poolCoinName = query.utils.parseCoinNameFromType<SupportPoolCoins>(
386
+ debt.type.name
387
+ );
388
+ return assetCoinName === poolCoinName;
389
+ });
390
+
391
+ const marketPool = market.pools[assetCoinName];
392
+ const coinDecimal = query.utils.getCoinDecimal(assetCoinName);
393
+ const coinPrice = coinPrices?.[assetCoinName];
394
+ const coinAmount = coinAmounts?.[assetCoinName] ?? 0;
386
395
 
387
396
  if (marketPool && coinPrice) {
388
- const increasedRate =
389
- marketPool.borrowIndex / Number(debt.borrowIndex) - 1;
390
- const borrowedAmount = BigNumber(debt.amount);
397
+ const increasedRate = debt?.borrowIndex
398
+ ? marketPool.borrowIndex / Number(debt.borrowIndex) - 1
399
+ : 0;
400
+ const borrowedAmount = BigNumber(debt?.amount ?? 0);
391
401
  const borrowedCoin = borrowedAmount.shiftedBy(-1 * coinDecimal);
392
- const availableRepayAmount = borrowedAmount.multipliedBy(
402
+
403
+ const requiredRepayAmount = borrowedAmount.multipliedBy(
393
404
  increasedRate + 1
394
405
  );
406
+ const requiredRepayCoin = requiredRepayAmount.shiftedBy(-1 * coinDecimal);
407
+
408
+ const availableRepayAmount = BigNumber(coinAmount);
395
409
  const availableRepayCoin = availableRepayAmount.shiftedBy(
396
410
  -1 * coinDecimal
397
411
  );
398
- const borrowedValue = availableRepayCoin.multipliedBy(coinPrice);
412
+
413
+ const borrowedValue = requiredRepayCoin.multipliedBy(coinPrice);
399
414
  const borrowedValueWithWeight = borrowedValue.multipliedBy(
400
415
  marketPool.borrowWeight
401
416
  );
@@ -409,17 +424,19 @@ export const getObligationAccount = async (
409
424
  totalBorrowedPools++;
410
425
  }
411
426
 
412
- debts[poolCoinName] = {
413
- coinName: poolCoinName,
414
- coinType: debt.type.name,
415
- symbol: query.utils.parseSymbol(poolCoinName),
427
+ debts[assetCoinName] = {
428
+ coinName: assetCoinName,
429
+ coinType: query.utils.parseCoinType(assetCoinName),
430
+ symbol: query.utils.parseSymbol(assetCoinName),
416
431
  coinDecimal: coinDecimal,
417
432
  coinPrice: coinPrice,
418
433
  borrowedAmount: borrowedAmount.toNumber(),
419
434
  borrowedCoin: borrowedCoin.toNumber(),
420
435
  borrowedValue: borrowedValue.toNumber(),
421
436
  borrowedValueWithWeight: borrowedValueWithWeight.toNumber(),
422
- borrowIndex: Number(debt.borrowIndex),
437
+ borrowIndex: Number(debt?.borrowIndex ?? 0),
438
+ requiredRepayAmount: requiredRepayAmount.toNumber(),
439
+ requiredRepayCoin: requiredRepayCoin.toNumber(),
423
440
  availableBorrowAmount: 0,
424
441
  availableBorrowCoin: 0,
425
442
  availableRepayAmount: availableRepayAmount.toNumber(),
@@ -472,16 +489,11 @@ export const getObligationAccount = async (
472
489
  }
473
490
  }
474
491
 
475
- let riskLevel =
476
- totalRequiredCollateralValue.isZero() &&
477
- totalBorrowedValueWithWeight.isZero()
478
- ? BigNumber(0)
479
- : totalBorrowedValueWithWeight.dividedBy(totalRequiredCollateralValue);
480
- riskLevel = riskLevel.isFinite()
481
- ? riskLevel.isLessThan(1)
482
- ? riskLevel
483
- : BigNumber(1)
484
- : BigNumber(1);
492
+ let riskLevel = totalRequiredCollateralValue.isZero()
493
+ ? BigNumber(0)
494
+ : totalBorrowedValueWithWeight.dividedBy(totalRequiredCollateralValue);
495
+ // Note: 100% represents the safety upper limit. Even if it exceeds 100% before it is liquidated, it will only display 100%.
496
+ riskLevel = riskLevel.isLessThan(1) ? riskLevel : BigNumber(1);
485
497
 
486
498
  const accountBalanceValue = totalDepositedValue
487
499
  .minus(totalBorrowedValue)
@@ -534,24 +546,38 @@ export const getObligationAccount = async (
534
546
  const marketCollateral =
535
547
  market.collaterals[collateralCoinName as SupportCollateralCoins];
536
548
  if (marketCollateral) {
537
- const availableWithdrawAmount =
549
+ let estimatedAvailableWithdrawAmount = BigNumber(
550
+ obligationAccount.totalAvailableCollateralValue
551
+ )
552
+ .dividedBy(marketCollateral.collateralFactor)
553
+ .dividedBy(marketCollateral.coinPrice)
554
+ .shiftedBy(marketCollateral.coinDecimal);
555
+ estimatedAvailableWithdrawAmount =
538
556
  obligationAccount.totalBorrowedValueWithWeight === 0
539
- ? BigNumber(obligationCollateral.depositedAmount)
557
+ ? // Note: when there is no debt record, there is no need to estimate and the deposited amount is directly used as available withdraw.
558
+ BigNumber(obligationCollateral.depositedAmount)
540
559
  : minBigNumber(
541
- BigNumber(obligationAccount.totalAvailableCollateralValue)
542
- .dividedBy(marketCollateral.collateralFactor)
543
- .dividedBy(marketCollateral.coinPrice)
560
+ estimatedAvailableWithdrawAmount
544
561
  // Note: reduced chance of failure when calculations are inaccurate
545
- .multipliedBy(0.99)
562
+ .multipliedBy(
563
+ estimatedFactor(
564
+ BigNumber(obligationAccount.totalAvailableCollateralValue)
565
+ .dividedBy(marketCollateral.collateralFactor)
566
+ .toNumber(),
567
+ 3,
568
+ 'increase'
569
+ )
570
+ )
546
571
  .toNumber(),
547
572
  obligationCollateral.depositedAmount,
548
573
  marketCollateral.depositAmount
549
574
  );
550
575
  obligationCollateral.availableWithdrawAmount =
551
- availableWithdrawAmount.toNumber();
552
- obligationCollateral.availableWithdrawCoin = availableWithdrawAmount
553
- .shiftedBy(-1 * obligationCollateral.coinDecimal)
554
- .toNumber();
576
+ estimatedAvailableWithdrawAmount.toNumber();
577
+ obligationCollateral.availableWithdrawCoin =
578
+ estimatedAvailableWithdrawAmount
579
+ .shiftedBy(-1 * obligationCollateral.coinDecimal)
580
+ .toNumber();
555
581
  }
556
582
  }
557
583
  for (const [poolCoinName, obligationDebt] of Object.entries(
@@ -559,33 +585,49 @@ export const getObligationAccount = async (
559
585
  )) {
560
586
  const marketPool = market.pools[poolCoinName as SupportPoolCoins];
561
587
  if (marketPool) {
562
- const availableRepayAmount = BigNumber(
563
- obligationDebt.availableRepayAmount
588
+ const estimatedRequiredRepayAmount = BigNumber(
589
+ obligationDebt.requiredRepayAmount
564
590
  )
565
- // Note: reduced chance of failure when calculations are inaccurate
566
- .multipliedBy(1.01);
567
-
568
- const availableBorrowAmount =
591
+ // Note: reduced chance of not being able to repay in full when calculations are inaccurate,
592
+ // and the contract will not actually take the excess amount.
593
+ .multipliedBy(
594
+ estimatedFactor(obligationDebt.borrowedValue, 3, 'decrease')
595
+ );
596
+
597
+ let estimatedAvailableBorrowAmount = BigNumber(
598
+ obligationAccount.totalAvailableCollateralValue
599
+ )
600
+ .dividedBy(marketPool.borrowWeight)
601
+ .shiftedBy(marketPool.coinDecimal)
602
+ .dividedBy(marketPool.coinPrice);
603
+ estimatedAvailableBorrowAmount =
569
604
  obligationAccount.totalAvailableCollateralValue !== 0
570
605
  ? minBigNumber(
571
- BigNumber(obligationAccount.totalAvailableCollateralValue)
572
- .dividedBy(
573
- BigNumber(marketPool.coinPrice).multipliedBy(
574
- marketPool.borrowWeight
606
+ estimatedAvailableBorrowAmount
607
+ // Note: reduced chance of failure when calculations are inaccurate
608
+ .multipliedBy(
609
+ estimatedFactor(
610
+ estimatedAvailableBorrowAmount
611
+ .shiftedBy(-1 * marketPool.coinDecimal)
612
+ .multipliedBy(marketPool.coinPrice)
613
+ .toNumber(),
614
+ 3,
615
+ 'increase'
575
616
  )
576
617
  )
577
- // Note: reduced chance of failure when calculations are inaccurate
578
- .multipliedBy(0.99)
579
618
  .toNumber(),
580
619
  marketPool.supplyAmount
581
620
  )
582
621
  : BigNumber(0);
583
- obligationDebt.availableBorrowAmount = availableBorrowAmount.toNumber();
584
- obligationDebt.availableBorrowCoin = availableBorrowAmount
622
+
623
+ obligationDebt.availableBorrowAmount =
624
+ estimatedAvailableBorrowAmount.toNumber();
625
+ obligationDebt.availableBorrowCoin = estimatedAvailableBorrowAmount
585
626
  .shiftedBy(-1 * obligationDebt.coinDecimal)
586
627
  .toNumber();
587
- obligationDebt.availableRepayAmount = availableRepayAmount.toNumber();
588
- obligationDebt.availableRepayCoin = availableRepayAmount
628
+ obligationDebt.requiredRepayAmount =
629
+ estimatedRequiredRepayAmount.toNumber();
630
+ obligationDebt.requiredRepayCoin = estimatedRequiredRepayAmount
589
631
  .shiftedBy(-1 * obligationDebt.coinDecimal)
590
632
  .toNumber();
591
633
  }
@@ -99,6 +99,8 @@ export type ObligationDebt = {
99
99
  borrowedValue: number;
100
100
  borrowedValueWithWeight: number;
101
101
  borrowIndex: number;
102
+ requiredRepayAmount: number;
103
+ requiredRepayCoin: number;
102
104
  availableBorrowAmount: number;
103
105
  availableBorrowCoin: number;
104
106
  availableRepayAmount: number;
@@ -612,3 +612,29 @@ export const maxBigNumber = (...args: BigNumber.Value[]) => {
612
612
  )
613
613
  );
614
614
  };
615
+
616
+ /**
617
+ * Dynamically adjust the decrease or increase ratio according to the amout
618
+ * @param amount - The amount required to calculate factor.
619
+ * @param scaleStep - The scale step required to determine the factor..
620
+ * @param type - The type of the calculation.
621
+ * @return The estimated factor
622
+ * */
623
+ export const estimatedFactor = (
624
+ amount: number,
625
+ scaleStep: number,
626
+ type: 'increase' | 'decrease'
627
+ ) => {
628
+ const amountOfDigits = Math.max(
629
+ 1,
630
+ Math.floor(Math.log10(Math.abs(amount)) + 1)
631
+ );
632
+
633
+ const adjustScale =
634
+ Math.max(Math.floor((amountOfDigits - 1) / scaleStep), 1) + 1;
635
+
636
+ let adjustFactor = Math.pow(10, -adjustScale);
637
+ adjustFactor = type === 'increase' ? 1 - adjustFactor : 1 + adjustFactor;
638
+
639
+ return adjustFactor;
640
+ };