@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/constants/enum.d.ts +3 -1
- package/dist/index.js +183 -109
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +153 -81
- package/dist/index.mjs.map +1 -1
- package/dist/models/scallopUtils.d.ts +1 -0
- package/dist/types/constant/enum.d.ts +8 -0
- package/dist/types/query/core.d.ts +2 -2
- package/dist/types/query/portfolio.d.ts +53 -36
- package/dist/types/query/spool.d.ts +3 -3
- package/dist/utils/query.d.ts +3 -0
- package/package.json +1 -1
- package/src/constants/enum.ts +22 -0
- package/src/models/scallopUtils.ts +36 -13
- package/src/queries/coreQuery.ts +4 -0
- package/src/queries/portfolioQuery.ts +115 -68
- package/src/queries/spoolQuery.ts +2 -2
- package/src/types/constant/enum.ts +13 -0
- package/src/types/query/core.ts +3 -1
- package/src/types/query/portfolio.ts +56 -45
- package/src/types/query/spool.ts +3 -3
- package/src/utils/query.ts +22 -6
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
|
|
657
|
+
const reserveAmount = BigNumber(parsedMarketPoolData.reserveAmount).plus(
|
|
640
658
|
increasedDebtAmount.multipliedBy(parsedMarketPoolData.reserveFactor)
|
|
641
659
|
);
|
|
642
|
-
const reserveCoin =
|
|
660
|
+
const reserveCoin = reserveAmount.shiftedBy(-1 * coinDecimal);
|
|
643
661
|
const supplyAmount = BigNumber(borrowAmount).plus(
|
|
644
|
-
Math.max(parsedMarketPoolData.cashAmount -
|
|
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:
|
|
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
|
|
817
|
+
const rewardRate = rewardValueForYear.dividedBy(calculatedStakePoolData.stakedValue).isFinite() ? rewardValueForYear.dividedBy(calculatedStakePoolData.stakedValue).toNumber() : Infinity;
|
|
800
818
|
return {
|
|
801
|
-
|
|
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
|
-
|
|
1448
|
-
symbol: query.utils.parseSymbol(
|
|
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?.
|
|
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
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
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
|
-
|
|
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
|
|
1824
|
-
let
|
|
1878
|
+
let totalDepositedPools = 0;
|
|
1879
|
+
let totalDepositedValue = BigNumber3(0);
|
|
1825
1880
|
let totalBorrowCapacityValue = BigNumber3(0);
|
|
1826
1881
|
let totalRequiredCollateralValue = BigNumber3(0);
|
|
1827
|
-
let
|
|
1828
|
-
let
|
|
1829
|
-
let
|
|
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
|
|
1840
|
-
const
|
|
1841
|
-
const
|
|
1842
|
-
const borrowCapacityValue =
|
|
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 =
|
|
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
|
-
|
|
1907
|
+
totalDepositedValue = totalDepositedValue.plus(depositedValue);
|
|
1853
1908
|
totalBorrowCapacityValue = totalBorrowCapacityValue.plus(borrowCapacityValue);
|
|
1854
1909
|
totalRequiredCollateralValue = totalRequiredCollateralValue.plus(
|
|
1855
1910
|
requiredCollateralValue2
|
|
1856
1911
|
);
|
|
1857
|
-
if (
|
|
1858
|
-
|
|
1912
|
+
if (depositedAmount.isGreaterThan(0)) {
|
|
1913
|
+
totalDepositedPools++;
|
|
1859
1914
|
}
|
|
1860
1915
|
collaterals[collateralCoinName] = {
|
|
1861
1916
|
coinName: collateralCoinName,
|
|
1862
1917
|
coinType: collateral.type.name,
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
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
|
|
1885
|
-
const
|
|
1886
|
-
const availableRepayAmount =
|
|
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
|
|
1891
|
-
const
|
|
1950
|
+
const borrowedValue = availableRepayCoin.multipliedBy(coinPrice);
|
|
1951
|
+
const borrowedValueWithWeight = borrowedValue.multipliedBy(
|
|
1892
1952
|
marketPool.borrowWeight
|
|
1893
1953
|
);
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
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
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
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() &&
|
|
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 =
|
|
1917
|
-
const availableCollateralValue = totalBorrowCapacityValue.minus(
|
|
1918
|
-
const requiredCollateralValue =
|
|
1919
|
-
const unhealthyCollateralValue =
|
|
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
|
-
|
|
1988
|
+
totalDepositedValue: totalDepositedValue.toNumber(),
|
|
1924
1989
|
// Borrowed debt value (liabilities balance)
|
|
1925
|
-
|
|
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
|
-
|
|
1996
|
+
totalAvailableCollateralValue: availableCollateralValue.toNumber(),
|
|
1932
1997
|
// Available debt value (the actual borrowing value included in the calculation).
|
|
1933
|
-
|
|
1998
|
+
totalBorrowedValueWithWeight: totalBorrowedValueWithWeight.toNumber(),
|
|
1934
1999
|
// Required collateral value (avoid be liquidated).
|
|
1935
|
-
|
|
2000
|
+
totalRequiredCollateralValue: requiredCollateralValue.toNumber(),
|
|
1936
2001
|
// Unliquidated collateral value (pending liquidation).
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
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.
|
|
1950
|
-
BigNumber3(obligationAccount.
|
|
1951
|
-
obligationCollateral.
|
|
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)
|
|
1966
|
-
const availableBorrowAmount = obligationAccount.
|
|
1967
|
-
BigNumber3(obligationAccount.
|
|
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.
|
|
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
|