@scallop-io/sui-scallop-sdk 0.42.6 → 0.42.8

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.mjs CHANGED
@@ -89,6 +89,24 @@ var rewardCoins = {
89
89
  susdc: "sui",
90
90
  susdt: "sui"
91
91
  };
92
+ var coinIds = {
93
+ sui: "0x0000000000000000000000000000000000000000000000000000000000000002",
94
+ eth: "0xaf8cd5edc19c4512f4259f0bee101a40d41ebed738ade5874359610ef8eeced5",
95
+ btc: "0x027792d9fed7f9844eb4839566001bb6f6cb4804f66aa2da6fe1ee242d896881",
96
+ usdc: "0x5d4b302506645c37ff133b98c4b50a5ae14841659738d6d733d59d0d217a93bf",
97
+ usdt: "0xc060006111016b8a020ad5b33834984a437aaa7d3c74c18e09a95d48aceab08c",
98
+ apt: "0x3a5143bb1196e3bcdfab6203d1683ae29edd26294fc8bfeafe4aaa9d2704df37",
99
+ sol: "0xb7844e289a8410e50fb3ca48d69eb9cf29e27d223ef90353fe1bd8e27ff8f3f8",
100
+ cetus: "0x06864a6f921804860930db6ddbe2e16acdf8504495ea7481637a1c8b9a8fe54b"
101
+ };
102
+ var wormholeCoinIds = {
103
+ eth: "0xaf8cd5edc19c4512f4259f0bee101a40d41ebed738ade5874359610ef8eeced5",
104
+ btc: "0x027792d9fed7f9844eb4839566001bb6f6cb4804f66aa2da6fe1ee242d896881",
105
+ usdc: "0x5d4b302506645c37ff133b98c4b50a5ae14841659738d6d733d59d0d217a93bf",
106
+ usdt: "0xc060006111016b8a020ad5b33834984a437aaa7d3c74c18e09a95d48aceab08c",
107
+ apt: "0x3a5143bb1196e3bcdfab6203d1683ae29edd26294fc8bfeafe4aaa9d2704df37",
108
+ sol: "0xb7844e289a8410e50fb3ca48d69eb9cf29e27d223ef90353fe1bd8e27ff8f3f8"
109
+ };
92
110
 
93
111
  // src/models/scallop.ts
94
112
  import { SuiKit as SuiKit5 } from "@scallop-io/sui-kit";
@@ -636,12 +654,12 @@ var calculateMarketPoolData = (utils, parsedMarketPoolData) => {
636
654
  parsedMarketPoolData.debtAmount
637
655
  );
638
656
  const borrowCoin = borrowAmount.shiftedBy(-1 * coinDecimal);
639
- const teserveAmount = BigNumber(parsedMarketPoolData.reserveAmount).plus(
657
+ const reserveAmount = BigNumber(parsedMarketPoolData.reserveAmount).plus(
640
658
  increasedDebtAmount.multipliedBy(parsedMarketPoolData.reserveFactor)
641
659
  );
642
- const reserveCoin = teserveAmount.shiftedBy(-1 * coinDecimal);
660
+ const reserveCoin = reserveAmount.shiftedBy(-1 * coinDecimal);
643
661
  const supplyAmount = BigNumber(borrowAmount).plus(
644
- Math.max(parsedMarketPoolData.cashAmount - teserveAmount.toNumber(), 0)
662
+ Math.max(parsedMarketPoolData.cashAmount - reserveAmount.toNumber(), 0)
645
663
  );
646
664
  const supplyCoin = supplyAmount.shiftedBy(-1 * coinDecimal);
647
665
  let utilizationRate = BigNumber(borrowAmount).dividedBy(supplyAmount);
@@ -672,7 +690,7 @@ var calculateMarketPoolData = (utils, parsedMarketPoolData) => {
672
690
  supplyCoin: supplyCoin.toNumber(),
673
691
  borrowAmount: borrowAmount.toNumber(),
674
692
  borrowCoin: borrowCoin.toNumber(),
675
- reserveAmount: teserveAmount.toNumber(),
693
+ reserveAmount: reserveAmount.toNumber(),
676
694
  reserveCoin: reserveCoin.toNumber(),
677
695
  utilizationRate: utilizationRate.toNumber(),
678
696
  supplyApr: supplyApr.toNumber(),
@@ -796,9 +814,9 @@ var calculateRewardPoolData = (parsedStakePoolData, parsedRewardPoolData, calcul
796
814
  );
797
815
  const claimedRewardValue = claimedRewardCoin.multipliedBy(rewardCoinPrice);
798
816
  const rewardValueForYear = BigNumber(rewardPerSec).shiftedBy(-1 * rewardCoinDecimal).multipliedBy(rateYearFactor).multipliedBy(rewardCoinPrice);
799
- const stakeRate = rewardValueForYear.dividedBy(calculatedStakePoolData.stakedValue).isFinite() ? rewardValueForYear.dividedBy(calculatedStakePoolData.stakedValue).toNumber() : Infinity;
817
+ const rewardRate = rewardValueForYear.dividedBy(calculatedStakePoolData.stakedValue).isFinite() ? rewardValueForYear.dividedBy(calculatedStakePoolData.stakedValue).toNumber() : Infinity;
800
818
  return {
801
- stakeApr: stakeRate,
819
+ rewardApr: rewardRate,
802
820
  totalRewardAmount: totalRewardAmount.toNumber(),
803
821
  totalRewardCoin: totalRewardCoin.toNumber(),
804
822
  totalRewardValue: totalRewardValue.toNumber(),
@@ -813,6 +831,13 @@ var calculateRewardPoolData = (parsedStakePoolData, parsedRewardPoolData, calcul
813
831
  exchangeRateDenominator: parsedRewardPoolData.exchangeRateDenominator
814
832
  };
815
833
  };
834
+ var minBigNumber = (...args) => {
835
+ return BigNumber(
836
+ args.reduce(
837
+ (min, current) => new BigNumber(current).lt(min) ? current : min
838
+ )
839
+ );
840
+ };
816
841
 
817
842
  // src/utils/util.ts
818
843
  var isMarketCoin = (coinName) => {
@@ -873,6 +898,8 @@ var queryMarket = async (query) => {
873
898
  coinWrappedType: query.utils.getCoinWrappedType(poolCoinName),
874
899
  coinDecimal: query.utils.getCoinDecimal(poolCoinName),
875
900
  coinPrice,
901
+ highKink: parsedMarketPoolData.highKink,
902
+ midKink: parsedMarketPoolData.midKink,
876
903
  reserveFactor: parsedMarketPoolData.reserveFactor,
877
904
  borrowWeight: parsedMarketPoolData.borrowWeight,
878
905
  marketCoinSupplyAmount: parsedMarketPoolData.marketCoinSupplyAmount,
@@ -1041,6 +1068,8 @@ var getMarketPool = async (query, poolCoinName, marketObject, coinPrice) => {
1041
1068
  coinWrappedType: query.utils.getCoinWrappedType(poolCoinName),
1042
1069
  coinDecimal: query.utils.getCoinDecimal(poolCoinName),
1043
1070
  coinPrice: coinPrice ?? 0,
1071
+ highKink: parsedMarketPoolData.highKink,
1072
+ midKink: parsedMarketPoolData.midKink,
1044
1073
  reserveFactor: parsedMarketPoolData.reserveFactor,
1045
1074
  borrowWeight: parsedMarketPoolData.borrowWeight,
1046
1075
  marketCoinSupplyAmount: parsedMarketPoolData.marketCoinSupplyAmount,
@@ -1444,8 +1473,8 @@ var getSpool = async (query, stakeMarketCoinName, marketPool) => {
1444
1473
  rewardCoinDecimal
1445
1474
  );
1446
1475
  spool = {
1447
- marketCoin: stakeMarketCoinName,
1448
- symbol: query.utils.parseSymbol(stakeCoinName),
1476
+ marketCoinName: stakeMarketCoinName,
1477
+ symbol: query.utils.parseSymbol(stakeMarketCoinName),
1449
1478
  coinType: query.utils.parseCoinType(stakeCoinName),
1450
1479
  marketCoinType: query.utils.parseMarketCoinType(stakeCoinName),
1451
1480
  rewardCoinType: isMarketCoin(rewardCoin) ? query.utils.parseMarketCoinType(rewardCoin) : query.utils.parseCoinType(rewardCoin),
@@ -1721,7 +1750,9 @@ var getLending = async (query, poolCoinName, ownerAddress, marketPool, spool, st
1721
1750
  let stakedCoin = BigNumber3(0);
1722
1751
  let stakedValue = BigNumber3(0);
1723
1752
  let availableUnstakeAmount = BigNumber3(0);
1753
+ let availableUnstakeCoin = BigNumber3(0);
1724
1754
  let availableClaimAmount = BigNumber3(0);
1755
+ let availableClaimCoin = BigNumber3(0);
1725
1756
  if (spool) {
1726
1757
  for (const stakeAccount of stakeAccounts) {
1727
1758
  const accountStakedMarketCoinAmount = BigNumber3(stakeAccount.staked);
@@ -1747,6 +1778,7 @@ var getLending = async (query, poolCoinName, ownerAddress, marketPool, spool, st
1747
1778
  availableUnstakeAmount = availableUnstakeAmount.plus(
1748
1779
  accountStakedMarketCoinAmount
1749
1780
  );
1781
+ availableUnstakeCoin = availableUnstakeAmount.shiftedBy(-1 * coinDecimal);
1750
1782
  const baseIndexRate = 1e9;
1751
1783
  const increasedPointRate = spool?.currentPointIndex ? BigNumber3(spool.currentPointIndex - stakeAccount.index).dividedBy(
1752
1784
  baseIndexRate
@@ -1754,6 +1786,7 @@ var getLending = async (query, poolCoinName, ownerAddress, marketPool, spool, st
1754
1786
  availableClaimAmount = availableClaimAmount.plus(
1755
1787
  BigNumber3(stakeAccount.staked).multipliedBy(increasedPointRate).plus(stakeAccount.points).multipliedBy(spool.exchangeRateNumerator).dividedBy(spool.exchangeRateDenominator)
1756
1788
  );
1789
+ availableClaimCoin = availableClaimAmount.shiftedBy(-1 * coinDecimal);
1757
1790
  }
1758
1791
  }
1759
1792
  const suppliedAmount = BigNumber3(marketCoinAmount).multipliedBy(
@@ -1761,6 +1794,18 @@ var getLending = async (query, poolCoinName, ownerAddress, marketPool, spool, st
1761
1794
  );
1762
1795
  const suppliedCoin = suppliedAmount.shiftedBy(-1 * coinDecimal);
1763
1796
  const suppliedValue = suppliedCoin.multipliedBy(coinPrice ?? 0);
1797
+ const unstakedMarketAmount = BigNumber3(marketCoinAmount);
1798
+ const unstakedMarketCoin = unstakedMarketAmount.shiftedBy(-1 * coinDecimal);
1799
+ const availableSupplyAmount = BigNumber3(coinAmount);
1800
+ const availableSupplyCoin = availableSupplyAmount.shiftedBy(-1 * coinDecimal);
1801
+ const availableWithdrawAmount = minBigNumber(
1802
+ suppliedAmount,
1803
+ marketPool?.supplyAmount ?? Infinity
1804
+ ).plus(stakedAmount);
1805
+ const availableWithdrawCoin = minBigNumber(
1806
+ suppliedCoin,
1807
+ marketPool?.supplyCoin ?? Infinity
1808
+ ).plus(stakedCoin);
1764
1809
  const lending = {
1765
1810
  coinName: poolCoinName,
1766
1811
  symbol: query.utils.parseSymbol(poolCoinName),
@@ -1770,7 +1815,7 @@ var getLending = async (query, poolCoinName, ownerAddress, marketPool, spool, st
1770
1815
  coinPrice: coinPrice ?? 0,
1771
1816
  supplyApr: marketPool?.supplyApr ?? 0,
1772
1817
  supplyApy: marketPool?.supplyApy ?? 0,
1773
- rewardApr: spool?.stakeApr ?? 0,
1818
+ rewardApr: spool?.rewardApr ?? 0,
1774
1819
  suppliedAmount: suppliedAmount.plus(stakedAmount).toNumber(),
1775
1820
  suppliedCoin: suppliedCoin.plus(stakedCoin).toNumber(),
1776
1821
  suppliedValue: suppliedValue.plus(stakedValue).toNumber(),
@@ -1779,11 +1824,21 @@ var getLending = async (query, poolCoinName, ownerAddress, marketPool, spool, st
1779
1824
  stakedAmount: stakedAmount.toNumber(),
1780
1825
  stakedCoin: stakedCoin.toNumber(),
1781
1826
  stakedValue: stakedValue.toNumber(),
1782
- availableSupplyAmount: coinAmount,
1783
- availableWithdrawAmount: 0,
1784
- availableStakeAmount: marketCoinAmount,
1827
+ unstakedMarketAmount: unstakedMarketAmount.toNumber(),
1828
+ unstakedMarketCoin: unstakedMarketCoin.toNumber(),
1829
+ unstakedAmount: suppliedAmount.toNumber(),
1830
+ unstakedCoin: suppliedCoin.toNumber(),
1831
+ unstakedValue: suppliedValue.toNumber(),
1832
+ availableSupplyAmount: availableSupplyAmount.toNumber(),
1833
+ availableSupplyCoin: availableSupplyCoin.toNumber(),
1834
+ availableWithdrawAmount: availableWithdrawAmount.toNumber(),
1835
+ availableWithdrawCoin: availableWithdrawCoin.toNumber(),
1836
+ availableStakeAmount: unstakedMarketAmount.toNumber(),
1837
+ availableStakeCoin: unstakedMarketCoin.toNumber(),
1785
1838
  availableUnstakeAmount: availableUnstakeAmount.toNumber(),
1786
- availableClaimAmount: availableClaimAmount.toNumber()
1839
+ availableUnstakeCoin: availableUnstakeCoin.toNumber(),
1840
+ availableClaimAmount: availableClaimAmount.toNumber(),
1841
+ availableClaimCoin: availableClaimCoin.toNumber()
1787
1842
  };
1788
1843
  return lending;
1789
1844
  };
@@ -1820,13 +1875,13 @@ var getObligationAccount = async (query, obligationId, ownerAddress, market, coi
1820
1875
  coinAmounts = coinAmounts || await query.getCoinAmounts(assetCoinNames, ownerAddress);
1821
1876
  const collaterals = {};
1822
1877
  const debts = {};
1823
- let totalCollateralPools = 0;
1824
- let totalCollateralValue = BigNumber3(0);
1878
+ let totalDepositedPools = 0;
1879
+ let totalDepositedValue = BigNumber3(0);
1825
1880
  let totalBorrowCapacityValue = BigNumber3(0);
1826
1881
  let totalRequiredCollateralValue = BigNumber3(0);
1827
- let totalDebtPools = 0;
1828
- let totalDebtValue = BigNumber3(0);
1829
- let totalDebtValueWithWeight = BigNumber3(0);
1882
+ let totalBorrowedPools = 0;
1883
+ let totalBorrowedValue = BigNumber3(0);
1884
+ let totalBorrowedValueWithWeight = BigNumber3(0);
1830
1885
  for (const collateral of obligationQuery.collaterals) {
1831
1886
  const collateralCoinName = query.utils.parseCoinNameFromType(
1832
1887
  collateral.type.name
@@ -1836,33 +1891,36 @@ var getObligationAccount = async (query, obligationId, ownerAddress, market, coi
1836
1891
  const coinPrice = coinPrices?.[collateralCoinName];
1837
1892
  const coinAmount = coinAmounts?.[collateralCoinName] ?? 0;
1838
1893
  if (marketCollateral && coinPrice) {
1839
- const collateralAmount = BigNumber3(collateral.amount);
1840
- const collateralCoin = collateralAmount.shiftedBy(-1 * coinDecimal);
1841
- const collateralValue = collateralCoin.multipliedBy(coinPrice);
1842
- const borrowCapacityValue = collateralValue.multipliedBy(
1894
+ const depositedAmount = BigNumber3(collateral.amount);
1895
+ const depositedCoin = depositedAmount.shiftedBy(-1 * coinDecimal);
1896
+ const depositedValue = depositedCoin.multipliedBy(coinPrice);
1897
+ const borrowCapacityValue = depositedValue.multipliedBy(
1843
1898
  marketCollateral.collateralFactor
1844
1899
  );
1845
- const requiredCollateralValue2 = collateralValue.multipliedBy(
1900
+ const requiredCollateralValue2 = depositedValue.multipliedBy(
1846
1901
  marketCollateral.liquidationFactor
1847
1902
  );
1848
1903
  const availableDepositAmount = BigNumber3(coinAmount);
1849
1904
  const availableDepositCoin = availableDepositAmount.shiftedBy(
1850
1905
  -1 * coinDecimal
1851
1906
  );
1852
- totalCollateralValue = totalCollateralValue.plus(collateralValue);
1907
+ totalDepositedValue = totalDepositedValue.plus(depositedValue);
1853
1908
  totalBorrowCapacityValue = totalBorrowCapacityValue.plus(borrowCapacityValue);
1854
1909
  totalRequiredCollateralValue = totalRequiredCollateralValue.plus(
1855
1910
  requiredCollateralValue2
1856
1911
  );
1857
- if (collateralAmount.isGreaterThan(0)) {
1858
- totalCollateralPools++;
1912
+ if (depositedAmount.isGreaterThan(0)) {
1913
+ totalDepositedPools++;
1859
1914
  }
1860
1915
  collaterals[collateralCoinName] = {
1861
1916
  coinName: collateralCoinName,
1862
1917
  coinType: collateral.type.name,
1863
- collateralAmount: collateralAmount.toNumber(),
1864
- collateralCoin: collateralCoin.toNumber(),
1865
- collateralValue: collateralValue.toNumber(),
1918
+ symbol: query.utils.parseSymbol(collateralCoinName),
1919
+ coinDecimal,
1920
+ coinPrice,
1921
+ depositedAmount: depositedAmount.toNumber(),
1922
+ depositedCoin: depositedCoin.toNumber(),
1923
+ depositedValue: depositedValue.toNumber(),
1866
1924
  borrowCapacityValue: borrowCapacityValue.toNumber(),
1867
1925
  requiredCollateralValue: requiredCollateralValue2.toNumber(),
1868
1926
  availableDepositAmount: availableDepositAmount.toNumber(),
@@ -1881,28 +1939,35 @@ var getObligationAccount = async (query, obligationId, ownerAddress, market, coi
1881
1939
  const coinPrice = coinPrices?.[poolCoinName];
1882
1940
  if (marketPool && coinPrice) {
1883
1941
  const increasedRate = marketPool.borrowIndex / Number(debt.borrowIndex) - 1;
1884
- const debtAmount = BigNumber3(debt.amount);
1885
- const debtCoin = debtAmount.shiftedBy(-1 * coinDecimal);
1886
- const availableRepayAmount = debtAmount.multipliedBy(increasedRate + 1);
1942
+ const borrowedAmount = BigNumber3(debt.amount);
1943
+ const borrowedCoin = borrowedAmount.shiftedBy(-1 * coinDecimal);
1944
+ const availableRepayAmount = borrowedAmount.multipliedBy(
1945
+ increasedRate + 1
1946
+ );
1887
1947
  const availableRepayCoin = availableRepayAmount.shiftedBy(
1888
1948
  -1 * coinDecimal
1889
1949
  );
1890
- const debtValue = availableRepayCoin.multipliedBy(coinPrice);
1891
- const debtValueWithWeight = debtValue.multipliedBy(
1950
+ const borrowedValue = availableRepayCoin.multipliedBy(coinPrice);
1951
+ const borrowedValueWithWeight = borrowedValue.multipliedBy(
1892
1952
  marketPool.borrowWeight
1893
1953
  );
1894
- totalDebtValue = totalDebtValue.plus(debtValue);
1895
- totalDebtValueWithWeight = totalDebtValueWithWeight.plus(debtValueWithWeight);
1896
- if (debtAmount.isGreaterThan(0)) {
1897
- totalDebtPools++;
1954
+ totalBorrowedValue = totalBorrowedValue.plus(borrowedValue);
1955
+ totalBorrowedValueWithWeight = totalBorrowedValueWithWeight.plus(
1956
+ borrowedValueWithWeight
1957
+ );
1958
+ if (borrowedAmount.isGreaterThan(0)) {
1959
+ totalBorrowedPools++;
1898
1960
  }
1899
1961
  debts[poolCoinName] = {
1900
1962
  coinName: poolCoinName,
1901
1963
  coinType: debt.type.name,
1902
- debtAmount: debtAmount.toNumber(),
1903
- debtCoin: debtCoin.toNumber(),
1904
- debtValue: debtValue.toNumber(),
1905
- debtValueWithWeight: debtValueWithWeight.toNumber(),
1964
+ symbol: query.utils.parseSymbol(poolCoinName),
1965
+ coinDecimal,
1966
+ coinPrice,
1967
+ borrowedAmount: borrowedAmount.toNumber(),
1968
+ borrowedCoin: borrowedCoin.toNumber(),
1969
+ borrowedValue: borrowedValue.toNumber(),
1970
+ borrowedValueWithWeight: borrowedValueWithWeight.toNumber(),
1906
1971
  borrowIndex: Number(debt.borrowIndex),
1907
1972
  availableBorrowAmount: 0,
1908
1973
  availableBorrowCoin: 0,
@@ -1911,33 +1976,33 @@ var getObligationAccount = async (query, obligationId, ownerAddress, market, coi
1911
1976
  };
1912
1977
  }
1913
1978
  }
1914
- let riskLevel = totalRequiredCollateralValue.isZero() && totalDebtValueWithWeight.isZero() ? BigNumber3(0) : totalDebtValueWithWeight.dividedBy(totalRequiredCollateralValue);
1979
+ let riskLevel = totalRequiredCollateralValue.isZero() && totalBorrowedValueWithWeight.isZero() ? BigNumber3(0) : totalBorrowedValueWithWeight.dividedBy(totalRequiredCollateralValue);
1915
1980
  riskLevel = riskLevel.isFinite() ? riskLevel.isLessThan(1) ? riskLevel : BigNumber3(1) : BigNumber3(1);
1916
- const accountBalanceValue = totalCollateralValue.minus(totalDebtValue).isGreaterThan(0) ? totalCollateralValue.minus(totalDebtValue) : BigNumber3(0);
1917
- const availableCollateralValue = totalBorrowCapacityValue.minus(totalDebtValueWithWeight).isGreaterThan(0) ? totalBorrowCapacityValue.minus(totalDebtValueWithWeight) : BigNumber3(0);
1918
- const requiredCollateralValue = totalDebtValueWithWeight.isGreaterThan(0) ? totalRequiredCollateralValue : BigNumber3(0);
1919
- const unhealthyCollateralValue = totalDebtValueWithWeight.minus(requiredCollateralValue).isGreaterThan(0) ? totalDebtValueWithWeight.minus(requiredCollateralValue) : BigNumber3(0);
1981
+ const accountBalanceValue = totalDepositedValue.minus(totalBorrowedValue).isGreaterThan(0) ? totalDepositedValue.minus(totalBorrowedValue) : BigNumber3(0);
1982
+ const availableCollateralValue = totalBorrowCapacityValue.minus(totalBorrowedValueWithWeight).isGreaterThan(0) ? totalBorrowCapacityValue.minus(totalBorrowedValueWithWeight) : BigNumber3(0);
1983
+ const requiredCollateralValue = totalBorrowedValueWithWeight.isGreaterThan(0) ? totalRequiredCollateralValue : BigNumber3(0);
1984
+ const unhealthyCollateralValue = totalBorrowedValueWithWeight.minus(requiredCollateralValue).isGreaterThan(0) ? totalBorrowedValueWithWeight.minus(requiredCollateralValue) : BigNumber3(0);
1920
1985
  const obligationAccount = {
1921
1986
  obligationId,
1922
1987
  // Deposited collateral value (collateral balance)
1923
- totalCollateralValue: totalCollateralValue.toNumber(),
1988
+ totalDepositedValue: totalDepositedValue.toNumber(),
1924
1989
  // Borrowed debt value (liabilities balance)
1925
- totalDebtValue: totalDebtValue.toNumber(),
1990
+ totalBorrowedValue: totalBorrowedValue.toNumber(),
1926
1991
  // The difference between the user’s actual deposit and loan (remaining balance)
1927
1992
  totalBalanceValue: accountBalanceValue.toNumber(),
1928
1993
  // Effective collateral value (the actual collateral value included in the calculation).
1929
1994
  totalBorrowCapacityValue: totalBorrowCapacityValue.toNumber(),
1930
1995
  // Available collateral value (the remaining collateral value that can be borrowed).
1931
- availableCollateralValue: availableCollateralValue.toNumber(),
1996
+ totalAvailableCollateralValue: availableCollateralValue.toNumber(),
1932
1997
  // Available debt value (the actual borrowing value included in the calculation).
1933
- totalDebtValueWithWeight: totalDebtValueWithWeight.toNumber(),
1998
+ totalBorrowedValueWithWeight: totalBorrowedValueWithWeight.toNumber(),
1934
1999
  // Required collateral value (avoid be liquidated).
1935
- requiredCollateralValue: requiredCollateralValue.toNumber(),
2000
+ totalRequiredCollateralValue: requiredCollateralValue.toNumber(),
1936
2001
  // Unliquidated collateral value (pending liquidation).
1937
- unhealthyCollateralValue: unhealthyCollateralValue.toNumber(),
1938
- riskLevel: riskLevel.toNumber(),
1939
- totalCollateralPools,
1940
- totalDebtPools,
2002
+ totalUnhealthyCollateralValue: unhealthyCollateralValue.toNumber(),
2003
+ totalRiskLevel: riskLevel.toNumber(),
2004
+ totalDepositedPools,
2005
+ totalBorrowedPools,
1941
2006
  collaterals,
1942
2007
  debts
1943
2008
  };
@@ -1946,13 +2011,13 @@ var getObligationAccount = async (query, obligationId, ownerAddress, market, coi
1946
2011
  )) {
1947
2012
  const marketCollateral = market.collaterals[collateralCoinName];
1948
2013
  if (marketCollateral) {
1949
- const availableWithdrawAmount = obligationAccount.totalDebtValueWithWeight === 0 ? obligationCollateral.collateralAmount : Math.min(
1950
- BigNumber3(obligationAccount.availableCollateralValue).dividedBy(marketCollateral.collateralFactor).dividedBy(marketCollateral.coinPrice).multipliedBy(0.99).toNumber(),
1951
- obligationCollateral.collateralAmount,
2014
+ const availableWithdrawAmount = obligationAccount.totalBorrowedValueWithWeight === 0 ? BigNumber3(obligationCollateral.depositedAmount) : minBigNumber(
2015
+ BigNumber3(obligationAccount.totalAvailableCollateralValue).dividedBy(marketCollateral.collateralFactor).dividedBy(marketCollateral.coinPrice).multipliedBy(0.99).toNumber(),
2016
+ obligationCollateral.depositedAmount,
1952
2017
  marketCollateral.depositAmount
1953
2018
  );
1954
- obligationCollateral.availableWithdrawAmount = availableWithdrawAmount;
1955
- obligationCollateral.availableWithdrawCoin = availableWithdrawAmount;
2019
+ obligationCollateral.availableWithdrawAmount = availableWithdrawAmount.toNumber();
2020
+ obligationCollateral.availableWithdrawCoin = availableWithdrawAmount.shiftedBy(-1 * obligationCollateral.coinDecimal).toNumber();
1956
2021
  }
1957
2022
  }
1958
2023
  for (const [assetCoinName, obligationDebt] of Object.entries(
@@ -1962,17 +2027,19 @@ var getObligationAccount = async (query, obligationId, ownerAddress, market, coi
1962
2027
  if (marketPool) {
1963
2028
  const availableRepayAmount = BigNumber3(
1964
2029
  obligationDebt.availableRepayAmount
1965
- ).multipliedBy(1.01).toNumber();
1966
- const availableBorrowAmount = obligationAccount.availableCollateralValue !== 0 ? Math.min(
1967
- BigNumber3(obligationAccount.availableCollateralValue).dividedBy(
2030
+ ).multipliedBy(1.01);
2031
+ const availableBorrowAmount = obligationAccount.totalAvailableCollateralValue !== 0 ? minBigNumber(
2032
+ BigNumber3(obligationAccount.totalAvailableCollateralValue).dividedBy(
1968
2033
  BigNumber3(marketPool.coinPrice).multipliedBy(
1969
2034
  marketPool.borrowWeight
1970
2035
  )
1971
2036
  ).multipliedBy(0.99).toNumber(),
1972
2037
  marketPool.supplyAmount
1973
- ) : 0;
1974
- obligationDebt.availableBorrowAmount = availableBorrowAmount;
1975
- obligationDebt.availableRepayAmount = availableRepayAmount;
2038
+ ) : BigNumber3(0);
2039
+ obligationDebt.availableBorrowAmount = availableBorrowAmount.toNumber();
2040
+ obligationDebt.availableBorrowCoin = availableBorrowAmount.shiftedBy(-1 * obligationDebt.coinDecimal).toNumber();
2041
+ obligationDebt.availableRepayAmount = availableRepayAmount.toNumber();
2042
+ obligationDebt.availableRepayCoin = availableRepayAmount.shiftedBy(-1 * obligationDebt.coinDecimal).toNumber();
1976
2043
  }
1977
2044
  }
1978
2045
  return obligationAccount;
@@ -2374,16 +2441,19 @@ var ScallopUtils = class {
2374
2441
  */
2375
2442
  parseCoinType(coinName) {
2376
2443
  coinName = isMarketCoin(coinName) ? this.parseCoinName(coinName) : coinName;
2377
- const coinPackageId = this._address.get(`core.coins.${coinName}.id`);
2444
+ const coinPackageId = this._address.get(`core.coins.${coinName}.id`) ?? coinIds[coinName] ?? void 0;
2445
+ if (!coinPackageId) {
2446
+ throw Error(`Coin ${coinName} is not supported`);
2447
+ }
2378
2448
  if (coinName === "sui")
2379
2449
  return normalizeStructTag2(`${coinPackageId}::sui::SUI`);
2380
2450
  const wormHoleCoinIds = [
2381
- this._address.get("core.coins.usdc.id"),
2382
- this._address.get("core.coins.usdt.id"),
2383
- this._address.get("core.coins.eth.id"),
2384
- this._address.get("core.coins.btc.id"),
2385
- this._address.get("core.coins.sol.id"),
2386
- this._address.get("core.coins.apt.id")
2451
+ this._address.get("core.coins.usdc.id") ?? wormholeCoinIds.usdc,
2452
+ this._address.get("core.coins.usdt.id") ?? wormholeCoinIds.usdt,
2453
+ this._address.get("core.coins.eth.id") ?? wormholeCoinIds.eth,
2454
+ this._address.get("core.coins.btc.id") ?? wormholeCoinIds.btc,
2455
+ this._address.get("core.coins.sol.id") ?? wormholeCoinIds.sol,
2456
+ this._address.get("core.coins.apt.id") ?? wormholeCoinIds.apt
2387
2457
  ];
2388
2458
  if (wormHoleCoinIds.includes(coinPackageId)) {
2389
2459
  return `${coinPackageId}::coin::COIN`;
@@ -2409,12 +2479,12 @@ var ScallopUtils = class {
2409
2479
  const isMarketCoinType = coinType.includes("reserve::MarketCoin");
2410
2480
  coinType = coinTypeMatch?.[1] || coinType;
2411
2481
  const wormHoleCoinTypeMap = {
2412
- [`${this._address.get("core.coins.usdc.id")}::coin::COIN`]: "usdc",
2413
- [`${this._address.get("core.coins.usdt.id")}::coin::COIN`]: "usdt",
2414
- [`${this._address.get("core.coins.eth.id")}::coin::COIN`]: "eth",
2415
- [`${this._address.get("core.coins.btc.id")}::coin::COIN`]: "btc",
2416
- [`${this._address.get("core.coins.sol.id")}::coin::COIN`]: "sol",
2417
- [`${this._address.get("core.coins.apt.id")}::coin::COIN`]: "apt"
2482
+ [`${this._address.get("core.coins.usdc.id") ?? wormholeCoinIds.usdc}::coin::COIN`]: "usdc",
2483
+ [`${this._address.get("core.coins.usdt.id") ?? wormholeCoinIds.usdt}::coin::COIN`]: "usdt",
2484
+ [`${this._address.get("core.coins.eth.id") ?? wormholeCoinIds.eth}::coin::COIN`]: "eth",
2485
+ [`${this._address.get("core.coins.btc.id") ?? wormholeCoinIds.btc}::coin::COIN`]: "btc",
2486
+ [`${this._address.get("core.coins.sol.id") ?? wormholeCoinIds.sol}::coin::COIN`]: "sol",
2487
+ [`${this._address.get("core.coins.apt.id") ?? wormholeCoinIds.apt}::coin::COIN`]: "apt"
2418
2488
  };
2419
2489
  const assetCoinName = wormHoleCoinTypeMap[coinType] || coinType.split("::")[2].toLowerCase();
2420
2490
  return isMarketCoinType ? this.parseMarketCoinName(assetCoinName) : assetCoinName;
@@ -3879,8 +3949,10 @@ export {
3879
3949
  ScallopUtils,
3880
3950
  assetCoins,
3881
3951
  coinDecimals,
3952
+ coinIds,
3882
3953
  marketCoins,
3883
3954
  rewardCoins,
3884
- stakeMarketCoins
3955
+ stakeMarketCoins,
3956
+ wormholeCoinIds
3885
3957
  };
3886
3958
  //# sourceMappingURL=index.mjs.map