@scallop-io/sui-scallop-sdk 0.42.6 → 0.42.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.
@@ -109,7 +109,7 @@ export type CollateralStat = {
109
109
  };
110
110
  export type MarketPool = {
111
111
  coinName: SupportPoolCoins;
112
- symbol: String;
112
+ symbol: string;
113
113
  coinType: string;
114
114
  marketCoinType: string;
115
115
  coinWrappedType: CoinWrappedType;
@@ -24,25 +24,25 @@ export type Lending = Required<Pick<MarketPool, 'coinName' | 'symbol' | 'coinTyp
24
24
  availableClaimAmount: number;
25
25
  };
26
26
  export type ObligationAccount = {
27
- obligationId?: string;
28
- obligationAccount?: ObligationAccount;
29
- totalCollateralValue: number;
30
- totalDebtValue: number;
27
+ obligationId: string;
28
+ totalDepositedValue: number;
29
+ totalBorrowedValue: number;
31
30
  totalBalanceValue: number;
32
31
  totalBorrowCapacityValue: number;
33
- availableCollateralValue: number;
34
- totalDebtValueWithWeight: number;
35
- requiredCollateralValue: number;
36
- unhealthyCollateralValue: number;
37
- riskLevel: number;
38
- totalCollateralPools: number;
39
- totalDebtPools: number;
40
- collaterals: OptionalKeys<Record<SupportPoolCoins, {
41
- coinName: string;
32
+ totalAvailableCollateralValue: number;
33
+ totalBorrowedValueWithWeight: number;
34
+ totalRequiredCollateralValue: number;
35
+ totalUnhealthyCollateralValue: number;
36
+ totalRiskLevel: number;
37
+ totalDepositedPools: number;
38
+ totalBorrowedPools: number;
39
+ collaterals: OptionalKeys<Record<SupportCollateralCoins, {
40
+ coinName: SupportCollateralCoins;
42
41
  coinType: string;
43
- collateralAmount: number;
44
- collateralCoin: number;
45
- collateralValue: number;
42
+ symbol: string;
43
+ depositedAmount: number;
44
+ depositedCoin: number;
45
+ depositedValue: number;
46
46
  borrowCapacityValue: number;
47
47
  requiredCollateralValue: number;
48
48
  availableDepositAmount: number;
@@ -50,13 +50,14 @@ export type ObligationAccount = {
50
50
  availableWithdrawAmount: number;
51
51
  availableWithdrawCoin: number;
52
52
  }>>;
53
- debts: OptionalKeys<Record<SupportCollateralCoins, {
54
- coinName: string;
53
+ debts: OptionalKeys<Record<SupportPoolCoins, {
54
+ coinName: SupportPoolCoins;
55
55
  coinType: string;
56
- debtAmount: number;
57
- debtCoin: number;
58
- debtValue: number;
59
- debtValueWithWeight: number;
56
+ symbol: string;
57
+ borrowedAmount: number;
58
+ borrowedCoin: number;
59
+ borrowedValue: number;
60
+ borrowedValueWithWeight: number;
60
61
  borrowIndex: number;
61
62
  availableBorrowAmount: number;
62
63
  availableBorrowCoin: number;
@@ -7,8 +7,8 @@ export type RewardPools = OptionalKeys<Record<SupportStakeMarketCoins, RewardPoo
7
7
  export type StakeAccounts = Record<SupportStakeMarketCoins, StakeAccount[]>;
8
8
  export type Spools = OptionalKeys<Record<SupportStakeMarketCoins, Spool>>;
9
9
  export type Spool = {
10
- marketCoin: SupportStakeMarketCoins;
11
- symbol: String;
10
+ marketCoinName: SupportStakeMarketCoins;
11
+ symbol: string;
12
12
  coinType: string;
13
13
  marketCoinType: string;
14
14
  rewardCoinType: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scallop-io/sui-scallop-sdk",
3
- "version": "0.42.6",
3
+ "version": "0.42.7",
4
4
  "description": "Typescript sdk for interacting with Scallop contract on SUI",
5
5
  "keywords": [
6
6
  "sui",
@@ -275,13 +275,13 @@ export const getObligationAccount = async (
275
275
 
276
276
  const collaterals: ObligationAccount['collaterals'] = {};
277
277
  const debts: ObligationAccount['debts'] = {};
278
- let totalCollateralPools = 0;
279
- let totalCollateralValue = BigNumber(0);
278
+ let totalDepositedPools = 0;
279
+ let totalDepositedValue = BigNumber(0);
280
280
  let totalBorrowCapacityValue = BigNumber(0);
281
281
  let totalRequiredCollateralValue = BigNumber(0);
282
- let totalDebtPools = 0;
283
- let totalDebtValue = BigNumber(0);
284
- let totalDebtValueWithWeight = BigNumber(0);
282
+ let totalBorrowedPools = 0;
283
+ let totalBorrowedValue = BigNumber(0);
284
+ let totalBorrowedValueWithWeight = BigNumber(0);
285
285
 
286
286
  for (const collateral of obligationQuery.collaterals) {
287
287
  const collateralCoinName =
@@ -294,13 +294,13 @@ export const getObligationAccount = async (
294
294
  const coinAmount = coinAmounts?.[collateralCoinName] ?? 0;
295
295
 
296
296
  if (marketCollateral && coinPrice) {
297
- const collateralAmount = BigNumber(collateral.amount);
298
- const collateralCoin = collateralAmount.shiftedBy(-1 * coinDecimal);
299
- const collateralValue = collateralCoin.multipliedBy(coinPrice);
300
- const borrowCapacityValue = collateralValue.multipliedBy(
297
+ const depositedAmount = BigNumber(collateral.amount);
298
+ const depositedCoin = depositedAmount.shiftedBy(-1 * coinDecimal);
299
+ const depositedValue = depositedCoin.multipliedBy(coinPrice);
300
+ const borrowCapacityValue = depositedValue.multipliedBy(
301
301
  marketCollateral.collateralFactor
302
302
  );
303
- const requiredCollateralValue = collateralValue.multipliedBy(
303
+ const requiredCollateralValue = depositedValue.multipliedBy(
304
304
  marketCollateral.liquidationFactor
305
305
  );
306
306
  const availableDepositAmount = BigNumber(coinAmount);
@@ -308,23 +308,24 @@ export const getObligationAccount = async (
308
308
  -1 * coinDecimal
309
309
  );
310
310
 
311
- totalCollateralValue = totalCollateralValue.plus(collateralValue);
311
+ totalDepositedValue = totalDepositedValue.plus(depositedValue);
312
312
  totalBorrowCapacityValue =
313
313
  totalBorrowCapacityValue.plus(borrowCapacityValue);
314
314
  totalRequiredCollateralValue = totalRequiredCollateralValue.plus(
315
315
  requiredCollateralValue
316
316
  );
317
317
 
318
- if (collateralAmount.isGreaterThan(0)) {
319
- totalCollateralPools++;
318
+ if (depositedAmount.isGreaterThan(0)) {
319
+ totalDepositedPools++;
320
320
  }
321
321
 
322
322
  collaterals[collateralCoinName] = {
323
323
  coinName: collateralCoinName,
324
324
  coinType: collateral.type.name,
325
- collateralAmount: collateralAmount.toNumber(),
326
- collateralCoin: collateralCoin.toNumber(),
327
- collateralValue: collateralValue.toNumber(),
325
+ symbol: query.utils.parseSymbol(collateralCoinName),
326
+ depositedAmount: depositedAmount.toNumber(),
327
+ depositedCoin: depositedCoin.toNumber(),
328
+ depositedValue: depositedValue.toNumber(),
328
329
  borrowCapacityValue: borrowCapacityValue.toNumber(),
329
330
  requiredCollateralValue: requiredCollateralValue.toNumber(),
330
331
  availableDepositAmount: availableDepositAmount.toNumber(),
@@ -346,32 +347,36 @@ export const getObligationAccount = async (
346
347
  if (marketPool && coinPrice) {
347
348
  const increasedRate =
348
349
  marketPool.borrowIndex / Number(debt.borrowIndex) - 1;
349
- const debtAmount = BigNumber(debt.amount);
350
- const debtCoin = debtAmount.shiftedBy(-1 * coinDecimal);
351
- const availableRepayAmount = debtAmount.multipliedBy(increasedRate + 1);
350
+ const borrowedAmount = BigNumber(debt.amount);
351
+ const borrowedCoin = borrowedAmount.shiftedBy(-1 * coinDecimal);
352
+ const availableRepayAmount = borrowedAmount.multipliedBy(
353
+ increasedRate + 1
354
+ );
352
355
  const availableRepayCoin = availableRepayAmount.shiftedBy(
353
356
  -1 * coinDecimal
354
357
  );
355
- const debtValue = availableRepayCoin.multipliedBy(coinPrice);
356
- const debtValueWithWeight = debtValue.multipliedBy(
358
+ const borrowedValue = availableRepayCoin.multipliedBy(coinPrice);
359
+ const borrowedValueWithWeight = borrowedValue.multipliedBy(
357
360
  marketPool.borrowWeight
358
361
  );
359
362
 
360
- totalDebtValue = totalDebtValue.plus(debtValue);
361
- totalDebtValueWithWeight =
362
- totalDebtValueWithWeight.plus(debtValueWithWeight);
363
+ totalBorrowedValue = totalBorrowedValue.plus(borrowedValue);
364
+ totalBorrowedValueWithWeight = totalBorrowedValueWithWeight.plus(
365
+ borrowedValueWithWeight
366
+ );
363
367
 
364
- if (debtAmount.isGreaterThan(0)) {
365
- totalDebtPools++;
368
+ if (borrowedAmount.isGreaterThan(0)) {
369
+ totalBorrowedPools++;
366
370
  }
367
371
 
368
372
  debts[poolCoinName] = {
369
373
  coinName: poolCoinName,
370
374
  coinType: debt.type.name,
371
- debtAmount: debtAmount.toNumber(),
372
- debtCoin: debtCoin.toNumber(),
373
- debtValue: debtValue.toNumber(),
374
- debtValueWithWeight: debtValueWithWeight.toNumber(),
375
+ symbol: query.utils.parseSymbol(poolCoinName),
376
+ borrowedAmount: borrowedAmount.toNumber(),
377
+ borrowedCoin: borrowedCoin.toNumber(),
378
+ borrowedValue: borrowedValue.toNumber(),
379
+ borrowedValueWithWeight: borrowedValueWithWeight.toNumber(),
375
380
  borrowIndex: Number(debt.borrowIndex),
376
381
  availableBorrowAmount: 0,
377
382
  availableBorrowCoin: 0,
@@ -382,55 +387,56 @@ export const getObligationAccount = async (
382
387
  }
383
388
 
384
389
  let riskLevel =
385
- totalRequiredCollateralValue.isZero() && totalDebtValueWithWeight.isZero()
390
+ totalRequiredCollateralValue.isZero() &&
391
+ totalBorrowedValueWithWeight.isZero()
386
392
  ? BigNumber(0)
387
- : totalDebtValueWithWeight.dividedBy(totalRequiredCollateralValue);
393
+ : totalBorrowedValueWithWeight.dividedBy(totalRequiredCollateralValue);
388
394
  riskLevel = riskLevel.isFinite()
389
395
  ? riskLevel.isLessThan(1)
390
396
  ? riskLevel
391
397
  : BigNumber(1)
392
398
  : BigNumber(1);
393
399
 
394
- const accountBalanceValue = totalCollateralValue
395
- .minus(totalDebtValue)
400
+ const accountBalanceValue = totalDepositedValue
401
+ .minus(totalBorrowedValue)
396
402
  .isGreaterThan(0)
397
- ? totalCollateralValue.minus(totalDebtValue)
403
+ ? totalDepositedValue.minus(totalBorrowedValue)
398
404
  : BigNumber(0);
399
405
  const availableCollateralValue = totalBorrowCapacityValue
400
- .minus(totalDebtValueWithWeight)
406
+ .minus(totalBorrowedValueWithWeight)
401
407
  .isGreaterThan(0)
402
- ? totalBorrowCapacityValue.minus(totalDebtValueWithWeight)
408
+ ? totalBorrowCapacityValue.minus(totalBorrowedValueWithWeight)
403
409
  : BigNumber(0);
404
- const requiredCollateralValue = totalDebtValueWithWeight.isGreaterThan(0)
410
+ const requiredCollateralValue = totalBorrowedValueWithWeight.isGreaterThan(0)
405
411
  ? totalRequiredCollateralValue
406
412
  : BigNumber(0);
407
- const unhealthyCollateralValue = totalDebtValueWithWeight
413
+ const unhealthyCollateralValue = totalBorrowedValueWithWeight
408
414
  .minus(requiredCollateralValue)
409
415
  .isGreaterThan(0)
410
- ? totalDebtValueWithWeight.minus(requiredCollateralValue)
416
+ ? totalBorrowedValueWithWeight.minus(requiredCollateralValue)
411
417
  : BigNumber(0);
412
418
 
413
419
  const obligationAccount: ObligationAccount = {
414
420
  obligationId: obligationId,
415
421
  // Deposited collateral value (collateral balance)
416
- totalCollateralValue: totalCollateralValue.toNumber(),
422
+ totalDepositedValue: totalDepositedValue.toNumber(),
417
423
  // Borrowed debt value (liabilities balance)
418
- totalDebtValue: totalDebtValue.toNumber(),
424
+ totalBorrowedValue: totalBorrowedValue.toNumber(),
419
425
  // The difference between the user’s actual deposit and loan (remaining balance)
420
426
  totalBalanceValue: accountBalanceValue.toNumber(),
421
427
  // Effective collateral value (the actual collateral value included in the calculation).
422
428
  totalBorrowCapacityValue: totalBorrowCapacityValue.toNumber(),
423
429
  // Available collateral value (the remaining collateral value that can be borrowed).
424
- availableCollateralValue: availableCollateralValue.toNumber(),
430
+ totalAvailableCollateralValue: availableCollateralValue.toNumber(),
425
431
  // Available debt value (the actual borrowing value included in the calculation).
426
- totalDebtValueWithWeight: totalDebtValueWithWeight.toNumber(),
432
+ totalBorrowedValueWithWeight: totalBorrowedValueWithWeight.toNumber(),
427
433
  // Required collateral value (avoid be liquidated).
428
- requiredCollateralValue: requiredCollateralValue.toNumber(),
434
+ totalRequiredCollateralValue: requiredCollateralValue.toNumber(),
429
435
  // Unliquidated collateral value (pending liquidation).
430
- unhealthyCollateralValue: unhealthyCollateralValue.toNumber(),
431
- riskLevel: riskLevel.toNumber(),
432
- totalCollateralPools,
433
- totalDebtPools,
436
+ totalUnhealthyCollateralValue: unhealthyCollateralValue.toNumber(),
437
+ totalRiskLevel: riskLevel.toNumber(),
438
+ totalDepositedPools,
439
+ totalBorrowedPools,
434
440
  collaterals,
435
441
  debts,
436
442
  };
@@ -442,16 +448,16 @@ export const getObligationAccount = async (
442
448
  market.collaterals[collateralCoinName as SupportCollateralCoins];
443
449
  if (marketCollateral) {
444
450
  const availableWithdrawAmount =
445
- obligationAccount.totalDebtValueWithWeight === 0
446
- ? obligationCollateral.collateralAmount
451
+ obligationAccount.totalBorrowedValueWithWeight === 0
452
+ ? obligationCollateral.depositedAmount
447
453
  : Math.min(
448
- BigNumber(obligationAccount.availableCollateralValue)
454
+ BigNumber(obligationAccount.totalAvailableCollateralValue)
449
455
  .dividedBy(marketCollateral.collateralFactor)
450
456
  .dividedBy(marketCollateral.coinPrice)
451
457
  // Note: reduced chance of failure when calculations are inaccurate
452
458
  .multipliedBy(0.99)
453
459
  .toNumber(),
454
- obligationCollateral.collateralAmount,
460
+ obligationCollateral.depositedAmount,
455
461
  marketCollateral.depositAmount
456
462
  );
457
463
  obligationCollateral.availableWithdrawAmount = availableWithdrawAmount;
@@ -471,9 +477,9 @@ export const getObligationAccount = async (
471
477
  .toNumber();
472
478
 
473
479
  const availableBorrowAmount =
474
- obligationAccount.availableCollateralValue !== 0
480
+ obligationAccount.totalAvailableCollateralValue !== 0
475
481
  ? Math.min(
476
- BigNumber(obligationAccount.availableCollateralValue)
482
+ BigNumber(obligationAccount.totalAvailableCollateralValue)
477
483
  .dividedBy(
478
484
  BigNumber(marketPool.coinPrice).multipliedBy(
479
485
  marketPool.borrowWeight
@@ -142,8 +142,8 @@ export const getSpool = async (
142
142
  );
143
143
 
144
144
  spool = {
145
- marketCoin: stakeMarketCoinName,
146
- symbol: query.utils.parseSymbol(stakeCoinName),
145
+ marketCoinName: stakeMarketCoinName,
146
+ symbol: query.utils.parseSymbol(stakeMarketCoinName),
147
147
  coinType: query.utils.parseCoinType(stakeCoinName),
148
148
  marketCoinType: query.utils.parseMarketCoinType(stakeCoinName),
149
149
  rewardCoinType: isMarketCoin(rewardCoin)
@@ -114,7 +114,7 @@ export type CollateralStat = { amount: string };
114
114
 
115
115
  export type MarketPool = {
116
116
  coinName: SupportPoolCoins;
117
- symbol: String;
117
+ symbol: string;
118
118
  coinType: string;
119
119
  marketCoinType: string;
120
120
  coinWrappedType: CoinWrappedType;
@@ -40,28 +40,28 @@ export type Lending = Required<
40
40
  };
41
41
 
42
42
  export type ObligationAccount = {
43
- obligationId?: string;
44
- obligationAccount?: ObligationAccount;
45
- totalCollateralValue: number;
46
- totalDebtValue: number;
43
+ obligationId: string;
44
+ totalDepositedValue: number;
45
+ totalBorrowedValue: number;
47
46
  totalBalanceValue: number;
48
47
  totalBorrowCapacityValue: number;
49
- availableCollateralValue: number;
50
- totalDebtValueWithWeight: number;
51
- requiredCollateralValue: number;
52
- unhealthyCollateralValue: number;
53
- riskLevel: number;
54
- totalCollateralPools: number;
55
- totalDebtPools: number;
48
+ totalAvailableCollateralValue: number;
49
+ totalBorrowedValueWithWeight: number;
50
+ totalRequiredCollateralValue: number;
51
+ totalUnhealthyCollateralValue: number;
52
+ totalRiskLevel: number;
53
+ totalDepositedPools: number;
54
+ totalBorrowedPools: number;
56
55
  collaterals: OptionalKeys<
57
56
  Record<
58
- SupportPoolCoins,
57
+ SupportCollateralCoins,
59
58
  {
60
- coinName: string;
59
+ coinName: SupportCollateralCoins;
61
60
  coinType: string;
62
- collateralAmount: number;
63
- collateralCoin: number;
64
- collateralValue: number;
61
+ symbol: string;
62
+ depositedAmount: number;
63
+ depositedCoin: number;
64
+ depositedValue: number;
65
65
  borrowCapacityValue: number;
66
66
  requiredCollateralValue: number;
67
67
  availableDepositAmount: number;
@@ -73,14 +73,15 @@ export type ObligationAccount = {
73
73
  >;
74
74
  debts: OptionalKeys<
75
75
  Record<
76
- SupportCollateralCoins,
76
+ SupportPoolCoins,
77
77
  {
78
- coinName: string;
78
+ coinName: SupportPoolCoins;
79
79
  coinType: string;
80
- debtAmount: number;
81
- debtCoin: number;
82
- debtValue: number;
83
- debtValueWithWeight: number;
80
+ symbol: string;
81
+ borrowedAmount: number;
82
+ borrowedCoin: number;
83
+ borrowedValue: number;
84
+ borrowedValueWithWeight: number;
84
85
  borrowIndex: number;
85
86
  availableBorrowAmount: number;
86
87
  availableBorrowCoin: number;
@@ -14,8 +14,8 @@ export type StakeAccounts = Record<SupportStakeMarketCoins, StakeAccount[]>;
14
14
  export type Spools = OptionalKeys<Record<SupportStakeMarketCoins, Spool>>;
15
15
 
16
16
  export type Spool = {
17
- marketCoin: SupportStakeMarketCoins;
18
- symbol: String;
17
+ marketCoinName: SupportStakeMarketCoins;
18
+ symbol: string;
19
19
  coinType: string;
20
20
  marketCoinType: string;
21
21
  rewardCoinType: string;
@@ -101,12 +101,12 @@ export const calculateMarketPoolData = (
101
101
  parsedMarketPoolData.debtAmount
102
102
  );
103
103
  const borrowCoin = borrowAmount.shiftedBy(-1 * coinDecimal);
104
- const teserveAmount = BigNumber(parsedMarketPoolData.reserveAmount).plus(
104
+ const reserveAmount = BigNumber(parsedMarketPoolData.reserveAmount).plus(
105
105
  increasedDebtAmount.multipliedBy(parsedMarketPoolData.reserveFactor)
106
106
  );
107
- const reserveCoin = teserveAmount.shiftedBy(-1 * coinDecimal);
107
+ const reserveCoin = reserveAmount.shiftedBy(-1 * coinDecimal);
108
108
  const supplyAmount = BigNumber(borrowAmount).plus(
109
- Math.max(parsedMarketPoolData.cashAmount - teserveAmount.toNumber(), 0)
109
+ Math.max(parsedMarketPoolData.cashAmount - reserveAmount.toNumber(), 0)
110
110
  );
111
111
  const supplyCoin = supplyAmount.shiftedBy(-1 * coinDecimal);
112
112
  let utilizationRate = BigNumber(borrowAmount).dividedBy(supplyAmount);
@@ -143,7 +143,7 @@ export const calculateMarketPoolData = (
143
143
  supplyCoin: supplyCoin.toNumber(),
144
144
  borrowAmount: borrowAmount.toNumber(),
145
145
  borrowCoin: borrowCoin.toNumber(),
146
- reserveAmount: teserveAmount.toNumber(),
146
+ reserveAmount: reserveAmount.toNumber(),
147
147
  reserveCoin: reserveCoin.toNumber(),
148
148
  utilizationRate: utilizationRate.toNumber(),
149
149
  supplyApr: supplyApr.toNumber(),