@scallop-io/sui-scallop-sdk 0.42.7 → 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 +125 -57
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +95 -29
- 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 +1 -1
- package/dist/types/query/portfolio.d.ts +44 -28
- package/dist/types/query/spool.d.ts +1 -1
- 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 +55 -14
- package/src/types/constant/enum.ts +13 -0
- package/src/types/query/core.ts +2 -0
- package/src/types/query/portfolio.ts +46 -36
- package/src/types/query/spool.ts +1 -1
- package/src/utils/query.ts +18 -2
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";
|
|
@@ -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,
|
|
@@ -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
|
};
|
|
@@ -1861,6 +1916,8 @@ var getObligationAccount = async (query, obligationId, ownerAddress, market, coi
|
|
|
1861
1916
|
coinName: collateralCoinName,
|
|
1862
1917
|
coinType: collateral.type.name,
|
|
1863
1918
|
symbol: query.utils.parseSymbol(collateralCoinName),
|
|
1919
|
+
coinDecimal,
|
|
1920
|
+
coinPrice,
|
|
1864
1921
|
depositedAmount: depositedAmount.toNumber(),
|
|
1865
1922
|
depositedCoin: depositedCoin.toNumber(),
|
|
1866
1923
|
depositedValue: depositedValue.toNumber(),
|
|
@@ -1905,6 +1962,8 @@ var getObligationAccount = async (query, obligationId, ownerAddress, market, coi
|
|
|
1905
1962
|
coinName: poolCoinName,
|
|
1906
1963
|
coinType: debt.type.name,
|
|
1907
1964
|
symbol: query.utils.parseSymbol(poolCoinName),
|
|
1965
|
+
coinDecimal,
|
|
1966
|
+
coinPrice,
|
|
1908
1967
|
borrowedAmount: borrowedAmount.toNumber(),
|
|
1909
1968
|
borrowedCoin: borrowedCoin.toNumber(),
|
|
1910
1969
|
borrowedValue: borrowedValue.toNumber(),
|
|
@@ -1952,13 +2011,13 @@ var getObligationAccount = async (query, obligationId, ownerAddress, market, coi
|
|
|
1952
2011
|
)) {
|
|
1953
2012
|
const marketCollateral = market.collaterals[collateralCoinName];
|
|
1954
2013
|
if (marketCollateral) {
|
|
1955
|
-
const availableWithdrawAmount = obligationAccount.totalBorrowedValueWithWeight === 0 ? obligationCollateral.depositedAmount :
|
|
2014
|
+
const availableWithdrawAmount = obligationAccount.totalBorrowedValueWithWeight === 0 ? BigNumber3(obligationCollateral.depositedAmount) : minBigNumber(
|
|
1956
2015
|
BigNumber3(obligationAccount.totalAvailableCollateralValue).dividedBy(marketCollateral.collateralFactor).dividedBy(marketCollateral.coinPrice).multipliedBy(0.99).toNumber(),
|
|
1957
2016
|
obligationCollateral.depositedAmount,
|
|
1958
2017
|
marketCollateral.depositAmount
|
|
1959
2018
|
);
|
|
1960
|
-
obligationCollateral.availableWithdrawAmount = availableWithdrawAmount;
|
|
1961
|
-
obligationCollateral.availableWithdrawCoin = availableWithdrawAmount;
|
|
2019
|
+
obligationCollateral.availableWithdrawAmount = availableWithdrawAmount.toNumber();
|
|
2020
|
+
obligationCollateral.availableWithdrawCoin = availableWithdrawAmount.shiftedBy(-1 * obligationCollateral.coinDecimal).toNumber();
|
|
1962
2021
|
}
|
|
1963
2022
|
}
|
|
1964
2023
|
for (const [assetCoinName, obligationDebt] of Object.entries(
|
|
@@ -1968,17 +2027,19 @@ var getObligationAccount = async (query, obligationId, ownerAddress, market, coi
|
|
|
1968
2027
|
if (marketPool) {
|
|
1969
2028
|
const availableRepayAmount = BigNumber3(
|
|
1970
2029
|
obligationDebt.availableRepayAmount
|
|
1971
|
-
).multipliedBy(1.01)
|
|
1972
|
-
const availableBorrowAmount = obligationAccount.totalAvailableCollateralValue !== 0 ?
|
|
2030
|
+
).multipliedBy(1.01);
|
|
2031
|
+
const availableBorrowAmount = obligationAccount.totalAvailableCollateralValue !== 0 ? minBigNumber(
|
|
1973
2032
|
BigNumber3(obligationAccount.totalAvailableCollateralValue).dividedBy(
|
|
1974
2033
|
BigNumber3(marketPool.coinPrice).multipliedBy(
|
|
1975
2034
|
marketPool.borrowWeight
|
|
1976
2035
|
)
|
|
1977
2036
|
).multipliedBy(0.99).toNumber(),
|
|
1978
2037
|
marketPool.supplyAmount
|
|
1979
|
-
) : 0;
|
|
1980
|
-
obligationDebt.availableBorrowAmount = availableBorrowAmount;
|
|
1981
|
-
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();
|
|
1982
2043
|
}
|
|
1983
2044
|
}
|
|
1984
2045
|
return obligationAccount;
|
|
@@ -2380,16 +2441,19 @@ var ScallopUtils = class {
|
|
|
2380
2441
|
*/
|
|
2381
2442
|
parseCoinType(coinName) {
|
|
2382
2443
|
coinName = isMarketCoin(coinName) ? this.parseCoinName(coinName) : coinName;
|
|
2383
|
-
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
|
+
}
|
|
2384
2448
|
if (coinName === "sui")
|
|
2385
2449
|
return normalizeStructTag2(`${coinPackageId}::sui::SUI`);
|
|
2386
2450
|
const wormHoleCoinIds = [
|
|
2387
|
-
this._address.get("core.coins.usdc.id"),
|
|
2388
|
-
this._address.get("core.coins.usdt.id"),
|
|
2389
|
-
this._address.get("core.coins.eth.id"),
|
|
2390
|
-
this._address.get("core.coins.btc.id"),
|
|
2391
|
-
this._address.get("core.coins.sol.id"),
|
|
2392
|
-
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
|
|
2393
2457
|
];
|
|
2394
2458
|
if (wormHoleCoinIds.includes(coinPackageId)) {
|
|
2395
2459
|
return `${coinPackageId}::coin::COIN`;
|
|
@@ -2415,12 +2479,12 @@ var ScallopUtils = class {
|
|
|
2415
2479
|
const isMarketCoinType = coinType.includes("reserve::MarketCoin");
|
|
2416
2480
|
coinType = coinTypeMatch?.[1] || coinType;
|
|
2417
2481
|
const wormHoleCoinTypeMap = {
|
|
2418
|
-
[`${this._address.get("core.coins.usdc.id")}::coin::COIN`]: "usdc",
|
|
2419
|
-
[`${this._address.get("core.coins.usdt.id")}::coin::COIN`]: "usdt",
|
|
2420
|
-
[`${this._address.get("core.coins.eth.id")}::coin::COIN`]: "eth",
|
|
2421
|
-
[`${this._address.get("core.coins.btc.id")}::coin::COIN`]: "btc",
|
|
2422
|
-
[`${this._address.get("core.coins.sol.id")}::coin::COIN`]: "sol",
|
|
2423
|
-
[`${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"
|
|
2424
2488
|
};
|
|
2425
2489
|
const assetCoinName = wormHoleCoinTypeMap[coinType] || coinType.split("::")[2].toLowerCase();
|
|
2426
2490
|
return isMarketCoinType ? this.parseMarketCoinName(assetCoinName) : assetCoinName;
|
|
@@ -3885,8 +3949,10 @@ export {
|
|
|
3885
3949
|
ScallopUtils,
|
|
3886
3950
|
assetCoins,
|
|
3887
3951
|
coinDecimals,
|
|
3952
|
+
coinIds,
|
|
3888
3953
|
marketCoins,
|
|
3889
3954
|
rewardCoins,
|
|
3890
|
-
stakeMarketCoins
|
|
3955
|
+
stakeMarketCoins,
|
|
3956
|
+
wormholeCoinIds
|
|
3891
3957
|
};
|
|
3892
3958
|
//# sourceMappingURL=index.mjs.map
|