@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.
package/dist/index.js CHANGED
@@ -691,12 +691,12 @@ var calculateMarketPoolData = (utils, parsedMarketPoolData) => {
691
691
  parsedMarketPoolData.debtAmount
692
692
  );
693
693
  const borrowCoin = borrowAmount.shiftedBy(-1 * coinDecimal);
694
- const teserveAmount = (0, import_bignumber.default)(parsedMarketPoolData.reserveAmount).plus(
694
+ const reserveAmount = (0, import_bignumber.default)(parsedMarketPoolData.reserveAmount).plus(
695
695
  increasedDebtAmount.multipliedBy(parsedMarketPoolData.reserveFactor)
696
696
  );
697
- const reserveCoin = teserveAmount.shiftedBy(-1 * coinDecimal);
697
+ const reserveCoin = reserveAmount.shiftedBy(-1 * coinDecimal);
698
698
  const supplyAmount = (0, import_bignumber.default)(borrowAmount).plus(
699
- Math.max(parsedMarketPoolData.cashAmount - teserveAmount.toNumber(), 0)
699
+ Math.max(parsedMarketPoolData.cashAmount - reserveAmount.toNumber(), 0)
700
700
  );
701
701
  const supplyCoin = supplyAmount.shiftedBy(-1 * coinDecimal);
702
702
  let utilizationRate = (0, import_bignumber.default)(borrowAmount).dividedBy(supplyAmount);
@@ -727,7 +727,7 @@ var calculateMarketPoolData = (utils, parsedMarketPoolData) => {
727
727
  supplyCoin: supplyCoin.toNumber(),
728
728
  borrowAmount: borrowAmount.toNumber(),
729
729
  borrowCoin: borrowCoin.toNumber(),
730
- reserveAmount: teserveAmount.toNumber(),
730
+ reserveAmount: reserveAmount.toNumber(),
731
731
  reserveCoin: reserveCoin.toNumber(),
732
732
  utilizationRate: utilizationRate.toNumber(),
733
733
  supplyApr: supplyApr.toNumber(),
@@ -1499,8 +1499,8 @@ var getSpool = async (query, stakeMarketCoinName, marketPool) => {
1499
1499
  rewardCoinDecimal
1500
1500
  );
1501
1501
  spool = {
1502
- marketCoin: stakeMarketCoinName,
1503
- symbol: query.utils.parseSymbol(stakeCoinName),
1502
+ marketCoinName: stakeMarketCoinName,
1503
+ symbol: query.utils.parseSymbol(stakeMarketCoinName),
1504
1504
  coinType: query.utils.parseCoinType(stakeCoinName),
1505
1505
  marketCoinType: query.utils.parseMarketCoinType(stakeCoinName),
1506
1506
  rewardCoinType: isMarketCoin(rewardCoin) ? query.utils.parseMarketCoinType(rewardCoin) : query.utils.parseCoinType(rewardCoin),
@@ -1875,13 +1875,13 @@ var getObligationAccount = async (query, obligationId, ownerAddress, market, coi
1875
1875
  coinAmounts = coinAmounts || await query.getCoinAmounts(assetCoinNames, ownerAddress);
1876
1876
  const collaterals = {};
1877
1877
  const debts = {};
1878
- let totalCollateralPools = 0;
1879
- let totalCollateralValue = (0, import_bignumber3.default)(0);
1878
+ let totalDepositedPools = 0;
1879
+ let totalDepositedValue = (0, import_bignumber3.default)(0);
1880
1880
  let totalBorrowCapacityValue = (0, import_bignumber3.default)(0);
1881
1881
  let totalRequiredCollateralValue = (0, import_bignumber3.default)(0);
1882
- let totalDebtPools = 0;
1883
- let totalDebtValue = (0, import_bignumber3.default)(0);
1884
- let totalDebtValueWithWeight = (0, import_bignumber3.default)(0);
1882
+ let totalBorrowedPools = 0;
1883
+ let totalBorrowedValue = (0, import_bignumber3.default)(0);
1884
+ let totalBorrowedValueWithWeight = (0, import_bignumber3.default)(0);
1885
1885
  for (const collateral of obligationQuery.collaterals) {
1886
1886
  const collateralCoinName = query.utils.parseCoinNameFromType(
1887
1887
  collateral.type.name
@@ -1891,33 +1891,34 @@ var getObligationAccount = async (query, obligationId, ownerAddress, market, coi
1891
1891
  const coinPrice = coinPrices?.[collateralCoinName];
1892
1892
  const coinAmount = coinAmounts?.[collateralCoinName] ?? 0;
1893
1893
  if (marketCollateral && coinPrice) {
1894
- const collateralAmount = (0, import_bignumber3.default)(collateral.amount);
1895
- const collateralCoin = collateralAmount.shiftedBy(-1 * coinDecimal);
1896
- const collateralValue = collateralCoin.multipliedBy(coinPrice);
1897
- const borrowCapacityValue = collateralValue.multipliedBy(
1894
+ const depositedAmount = (0, import_bignumber3.default)(collateral.amount);
1895
+ const depositedCoin = depositedAmount.shiftedBy(-1 * coinDecimal);
1896
+ const depositedValue = depositedCoin.multipliedBy(coinPrice);
1897
+ const borrowCapacityValue = depositedValue.multipliedBy(
1898
1898
  marketCollateral.collateralFactor
1899
1899
  );
1900
- const requiredCollateralValue2 = collateralValue.multipliedBy(
1900
+ const requiredCollateralValue2 = depositedValue.multipliedBy(
1901
1901
  marketCollateral.liquidationFactor
1902
1902
  );
1903
1903
  const availableDepositAmount = (0, import_bignumber3.default)(coinAmount);
1904
1904
  const availableDepositCoin = availableDepositAmount.shiftedBy(
1905
1905
  -1 * coinDecimal
1906
1906
  );
1907
- totalCollateralValue = totalCollateralValue.plus(collateralValue);
1907
+ totalDepositedValue = totalDepositedValue.plus(depositedValue);
1908
1908
  totalBorrowCapacityValue = totalBorrowCapacityValue.plus(borrowCapacityValue);
1909
1909
  totalRequiredCollateralValue = totalRequiredCollateralValue.plus(
1910
1910
  requiredCollateralValue2
1911
1911
  );
1912
- if (collateralAmount.isGreaterThan(0)) {
1913
- totalCollateralPools++;
1912
+ if (depositedAmount.isGreaterThan(0)) {
1913
+ totalDepositedPools++;
1914
1914
  }
1915
1915
  collaterals[collateralCoinName] = {
1916
1916
  coinName: collateralCoinName,
1917
1917
  coinType: collateral.type.name,
1918
- collateralAmount: collateralAmount.toNumber(),
1919
- collateralCoin: collateralCoin.toNumber(),
1920
- collateralValue: collateralValue.toNumber(),
1918
+ symbol: query.utils.parseSymbol(collateralCoinName),
1919
+ depositedAmount: depositedAmount.toNumber(),
1920
+ depositedCoin: depositedCoin.toNumber(),
1921
+ depositedValue: depositedValue.toNumber(),
1921
1922
  borrowCapacityValue: borrowCapacityValue.toNumber(),
1922
1923
  requiredCollateralValue: requiredCollateralValue2.toNumber(),
1923
1924
  availableDepositAmount: availableDepositAmount.toNumber(),
@@ -1936,28 +1937,33 @@ var getObligationAccount = async (query, obligationId, ownerAddress, market, coi
1936
1937
  const coinPrice = coinPrices?.[poolCoinName];
1937
1938
  if (marketPool && coinPrice) {
1938
1939
  const increasedRate = marketPool.borrowIndex / Number(debt.borrowIndex) - 1;
1939
- const debtAmount = (0, import_bignumber3.default)(debt.amount);
1940
- const debtCoin = debtAmount.shiftedBy(-1 * coinDecimal);
1941
- const availableRepayAmount = debtAmount.multipliedBy(increasedRate + 1);
1940
+ const borrowedAmount = (0, import_bignumber3.default)(debt.amount);
1941
+ const borrowedCoin = borrowedAmount.shiftedBy(-1 * coinDecimal);
1942
+ const availableRepayAmount = borrowedAmount.multipliedBy(
1943
+ increasedRate + 1
1944
+ );
1942
1945
  const availableRepayCoin = availableRepayAmount.shiftedBy(
1943
1946
  -1 * coinDecimal
1944
1947
  );
1945
- const debtValue = availableRepayCoin.multipliedBy(coinPrice);
1946
- const debtValueWithWeight = debtValue.multipliedBy(
1948
+ const borrowedValue = availableRepayCoin.multipliedBy(coinPrice);
1949
+ const borrowedValueWithWeight = borrowedValue.multipliedBy(
1947
1950
  marketPool.borrowWeight
1948
1951
  );
1949
- totalDebtValue = totalDebtValue.plus(debtValue);
1950
- totalDebtValueWithWeight = totalDebtValueWithWeight.plus(debtValueWithWeight);
1951
- if (debtAmount.isGreaterThan(0)) {
1952
- totalDebtPools++;
1952
+ totalBorrowedValue = totalBorrowedValue.plus(borrowedValue);
1953
+ totalBorrowedValueWithWeight = totalBorrowedValueWithWeight.plus(
1954
+ borrowedValueWithWeight
1955
+ );
1956
+ if (borrowedAmount.isGreaterThan(0)) {
1957
+ totalBorrowedPools++;
1953
1958
  }
1954
1959
  debts[poolCoinName] = {
1955
1960
  coinName: poolCoinName,
1956
1961
  coinType: debt.type.name,
1957
- debtAmount: debtAmount.toNumber(),
1958
- debtCoin: debtCoin.toNumber(),
1959
- debtValue: debtValue.toNumber(),
1960
- debtValueWithWeight: debtValueWithWeight.toNumber(),
1962
+ symbol: query.utils.parseSymbol(poolCoinName),
1963
+ borrowedAmount: borrowedAmount.toNumber(),
1964
+ borrowedCoin: borrowedCoin.toNumber(),
1965
+ borrowedValue: borrowedValue.toNumber(),
1966
+ borrowedValueWithWeight: borrowedValueWithWeight.toNumber(),
1961
1967
  borrowIndex: Number(debt.borrowIndex),
1962
1968
  availableBorrowAmount: 0,
1963
1969
  availableBorrowCoin: 0,
@@ -1966,33 +1972,33 @@ var getObligationAccount = async (query, obligationId, ownerAddress, market, coi
1966
1972
  };
1967
1973
  }
1968
1974
  }
1969
- let riskLevel = totalRequiredCollateralValue.isZero() && totalDebtValueWithWeight.isZero() ? (0, import_bignumber3.default)(0) : totalDebtValueWithWeight.dividedBy(totalRequiredCollateralValue);
1975
+ let riskLevel = totalRequiredCollateralValue.isZero() && totalBorrowedValueWithWeight.isZero() ? (0, import_bignumber3.default)(0) : totalBorrowedValueWithWeight.dividedBy(totalRequiredCollateralValue);
1970
1976
  riskLevel = riskLevel.isFinite() ? riskLevel.isLessThan(1) ? riskLevel : (0, import_bignumber3.default)(1) : (0, import_bignumber3.default)(1);
1971
- const accountBalanceValue = totalCollateralValue.minus(totalDebtValue).isGreaterThan(0) ? totalCollateralValue.minus(totalDebtValue) : (0, import_bignumber3.default)(0);
1972
- const availableCollateralValue = totalBorrowCapacityValue.minus(totalDebtValueWithWeight).isGreaterThan(0) ? totalBorrowCapacityValue.minus(totalDebtValueWithWeight) : (0, import_bignumber3.default)(0);
1973
- const requiredCollateralValue = totalDebtValueWithWeight.isGreaterThan(0) ? totalRequiredCollateralValue : (0, import_bignumber3.default)(0);
1974
- const unhealthyCollateralValue = totalDebtValueWithWeight.minus(requiredCollateralValue).isGreaterThan(0) ? totalDebtValueWithWeight.minus(requiredCollateralValue) : (0, import_bignumber3.default)(0);
1977
+ const accountBalanceValue = totalDepositedValue.minus(totalBorrowedValue).isGreaterThan(0) ? totalDepositedValue.minus(totalBorrowedValue) : (0, import_bignumber3.default)(0);
1978
+ const availableCollateralValue = totalBorrowCapacityValue.minus(totalBorrowedValueWithWeight).isGreaterThan(0) ? totalBorrowCapacityValue.minus(totalBorrowedValueWithWeight) : (0, import_bignumber3.default)(0);
1979
+ const requiredCollateralValue = totalBorrowedValueWithWeight.isGreaterThan(0) ? totalRequiredCollateralValue : (0, import_bignumber3.default)(0);
1980
+ const unhealthyCollateralValue = totalBorrowedValueWithWeight.minus(requiredCollateralValue).isGreaterThan(0) ? totalBorrowedValueWithWeight.minus(requiredCollateralValue) : (0, import_bignumber3.default)(0);
1975
1981
  const obligationAccount = {
1976
1982
  obligationId,
1977
1983
  // Deposited collateral value (collateral balance)
1978
- totalCollateralValue: totalCollateralValue.toNumber(),
1984
+ totalDepositedValue: totalDepositedValue.toNumber(),
1979
1985
  // Borrowed debt value (liabilities balance)
1980
- totalDebtValue: totalDebtValue.toNumber(),
1986
+ totalBorrowedValue: totalBorrowedValue.toNumber(),
1981
1987
  // The difference between the user’s actual deposit and loan (remaining balance)
1982
1988
  totalBalanceValue: accountBalanceValue.toNumber(),
1983
1989
  // Effective collateral value (the actual collateral value included in the calculation).
1984
1990
  totalBorrowCapacityValue: totalBorrowCapacityValue.toNumber(),
1985
1991
  // Available collateral value (the remaining collateral value that can be borrowed).
1986
- availableCollateralValue: availableCollateralValue.toNumber(),
1992
+ totalAvailableCollateralValue: availableCollateralValue.toNumber(),
1987
1993
  // Available debt value (the actual borrowing value included in the calculation).
1988
- totalDebtValueWithWeight: totalDebtValueWithWeight.toNumber(),
1994
+ totalBorrowedValueWithWeight: totalBorrowedValueWithWeight.toNumber(),
1989
1995
  // Required collateral value (avoid be liquidated).
1990
- requiredCollateralValue: requiredCollateralValue.toNumber(),
1996
+ totalRequiredCollateralValue: requiredCollateralValue.toNumber(),
1991
1997
  // Unliquidated collateral value (pending liquidation).
1992
- unhealthyCollateralValue: unhealthyCollateralValue.toNumber(),
1993
- riskLevel: riskLevel.toNumber(),
1994
- totalCollateralPools,
1995
- totalDebtPools,
1998
+ totalUnhealthyCollateralValue: unhealthyCollateralValue.toNumber(),
1999
+ totalRiskLevel: riskLevel.toNumber(),
2000
+ totalDepositedPools,
2001
+ totalBorrowedPools,
1996
2002
  collaterals,
1997
2003
  debts
1998
2004
  };
@@ -2001,9 +2007,9 @@ var getObligationAccount = async (query, obligationId, ownerAddress, market, coi
2001
2007
  )) {
2002
2008
  const marketCollateral = market.collaterals[collateralCoinName];
2003
2009
  if (marketCollateral) {
2004
- const availableWithdrawAmount = obligationAccount.totalDebtValueWithWeight === 0 ? obligationCollateral.collateralAmount : Math.min(
2005
- (0, import_bignumber3.default)(obligationAccount.availableCollateralValue).dividedBy(marketCollateral.collateralFactor).dividedBy(marketCollateral.coinPrice).multipliedBy(0.99).toNumber(),
2006
- obligationCollateral.collateralAmount,
2010
+ const availableWithdrawAmount = obligationAccount.totalBorrowedValueWithWeight === 0 ? obligationCollateral.depositedAmount : Math.min(
2011
+ (0, import_bignumber3.default)(obligationAccount.totalAvailableCollateralValue).dividedBy(marketCollateral.collateralFactor).dividedBy(marketCollateral.coinPrice).multipliedBy(0.99).toNumber(),
2012
+ obligationCollateral.depositedAmount,
2007
2013
  marketCollateral.depositAmount
2008
2014
  );
2009
2015
  obligationCollateral.availableWithdrawAmount = availableWithdrawAmount;
@@ -2018,8 +2024,8 @@ var getObligationAccount = async (query, obligationId, ownerAddress, market, coi
2018
2024
  const availableRepayAmount = (0, import_bignumber3.default)(
2019
2025
  obligationDebt.availableRepayAmount
2020
2026
  ).multipliedBy(1.01).toNumber();
2021
- const availableBorrowAmount = obligationAccount.availableCollateralValue !== 0 ? Math.min(
2022
- (0, import_bignumber3.default)(obligationAccount.availableCollateralValue).dividedBy(
2027
+ const availableBorrowAmount = obligationAccount.totalAvailableCollateralValue !== 0 ? Math.min(
2028
+ (0, import_bignumber3.default)(obligationAccount.totalAvailableCollateralValue).dividedBy(
2023
2029
  (0, import_bignumber3.default)(marketPool.coinPrice).multipliedBy(
2024
2030
  marketPool.borrowWeight
2025
2031
  )