@scallop-io/sui-scallop-sdk 0.44.3 → 0.44.4
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 +101 -56
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +73 -28
- package/dist/index.mjs.map +1 -1
- package/dist/types/query/portfolio.d.ts +13 -0
- package/package.json +1 -1
- package/src/queries/borrowIncentiveQuery.ts +2 -1
- package/src/queries/coreQuery.ts +3 -2
- package/src/queries/portfolioQuery.ts +59 -5
- package/src/queries/spoolQuery.ts +9 -9
- package/src/types/query/portfolio.ts +16 -0
- package/src/utils/query.ts +3 -3
package/dist/index.mjs
CHANGED
|
@@ -648,7 +648,7 @@ import { normalizeSuiAddress as normalizeSuiAddress2 } from "@mysten/sui.js/util
|
|
|
648
648
|
import { SuiKit as SuiKit4 } from "@scallop-io/sui-kit";
|
|
649
649
|
|
|
650
650
|
// src/models/scallopUtils.ts
|
|
651
|
-
import { SUI_TYPE_ARG, normalizeStructTag as
|
|
651
|
+
import { SUI_TYPE_ARG, normalizeStructTag as normalizeStructTag5 } from "@mysten/sui.js/utils";
|
|
652
652
|
import { SuiKit as SuiKit2 } from "@scallop-io/sui-kit";
|
|
653
653
|
import { SuiPriceServiceConnection } from "@pythnetwork/pyth-sui-js";
|
|
654
654
|
|
|
@@ -656,6 +656,7 @@ import { SuiPriceServiceConnection } from "@pythnetwork/pyth-sui-js";
|
|
|
656
656
|
import { SuiKit } from "@scallop-io/sui-kit";
|
|
657
657
|
|
|
658
658
|
// src/queries/coreQuery.ts
|
|
659
|
+
import { normalizeStructTag as normalizeStructTag2 } from "@mysten/sui.js/utils";
|
|
659
660
|
import { SuiTxBlock as SuiKitTxBlock } from "@scallop-io/sui-kit";
|
|
660
661
|
import BigNumber2 from "bignumber.js";
|
|
661
662
|
|
|
@@ -673,7 +674,7 @@ import BigNumber from "bignumber.js";
|
|
|
673
674
|
import { normalizeStructTag } from "@mysten/sui.js/utils";
|
|
674
675
|
var parseOriginMarketPoolData = (originMarketPoolData) => {
|
|
675
676
|
return {
|
|
676
|
-
coinType:
|
|
677
|
+
coinType: normalizeStructTag(originMarketPoolData.type.name),
|
|
677
678
|
// Parse origin data required for basic calculations.
|
|
678
679
|
maxBorrowRate: Number(originMarketPoolData.maxBorrowRate.value) / 2 ** 32,
|
|
679
680
|
borrowRate: Number(originMarketPoolData.interestRate.value) / 2 ** 32,
|
|
@@ -767,7 +768,7 @@ var calculateMarketPoolData = (utils, parsedMarketPoolData) => {
|
|
|
767
768
|
};
|
|
768
769
|
var parseOriginMarketCollateralData = (originMarketCollateralData) => {
|
|
769
770
|
return {
|
|
770
|
-
coinType:
|
|
771
|
+
coinType: normalizeStructTag(originMarketCollateralData.type.name),
|
|
771
772
|
collateralFactor: Number(originMarketCollateralData.collateralFactor.value) / 2 ** 32,
|
|
772
773
|
liquidationFactor: Number(originMarketCollateralData.liquidationFactor.value) / 2 ** 32,
|
|
773
774
|
liquidationDiscount: Number(originMarketCollateralData.liquidationDiscount.value) / 2 ** 32,
|
|
@@ -799,7 +800,7 @@ var calculateMarketCollateralData = (utils, parsedMarketCollateralData) => {
|
|
|
799
800
|
};
|
|
800
801
|
var parseOriginSpoolData = (originSpoolData) => {
|
|
801
802
|
return {
|
|
802
|
-
stakeType:
|
|
803
|
+
stakeType: normalizeStructTag(originSpoolData.stakeType.fields.name),
|
|
803
804
|
maxPoint: Number(originSpoolData.maxDistributedPoint),
|
|
804
805
|
distributedPoint: Number(originSpoolData.distributedPoint),
|
|
805
806
|
pointPerPeriod: Number(originSpoolData.distributedPointPerPeriod),
|
|
@@ -1088,7 +1089,7 @@ var queryMarket = async (query) => {
|
|
|
1088
1089
|
const pools = {};
|
|
1089
1090
|
const collaterals = {};
|
|
1090
1091
|
for (const pool of marketData.pools) {
|
|
1091
|
-
const coinType =
|
|
1092
|
+
const coinType = normalizeStructTag2(pool.type.name);
|
|
1092
1093
|
const poolCoinName = query.utils.parseCoinNameFromType(coinType);
|
|
1093
1094
|
const coinPrice = (await query.utils.getCoinPrices([poolCoinName]))?.[poolCoinName] ?? 0;
|
|
1094
1095
|
if (!SUPPORT_POOLS.includes(poolCoinName)) {
|
|
@@ -1136,7 +1137,7 @@ var queryMarket = async (query) => {
|
|
|
1136
1137
|
};
|
|
1137
1138
|
}
|
|
1138
1139
|
for (const collateral of marketData.collaterals) {
|
|
1139
|
-
const coinType =
|
|
1140
|
+
const coinType = normalizeStructTag2(collateral.type.name);
|
|
1140
1141
|
const collateralCoinName = query.utils.parseCoinNameFromType(coinType);
|
|
1141
1142
|
const coinPrice = (await query.utils.getCoinPrices([collateralCoinName]))?.[collateralCoinName] ?? 0;
|
|
1142
1143
|
if (!SUPPORT_COLLATERALS.includes(collateralCoinName)) {
|
|
@@ -1637,7 +1638,7 @@ var getMarketCoinAmount = async (query, marketCoinName, ownerAddress) => {
|
|
|
1637
1638
|
};
|
|
1638
1639
|
|
|
1639
1640
|
// src/queries/spoolQuery.ts
|
|
1640
|
-
import { normalizeStructTag as
|
|
1641
|
+
import { normalizeStructTag as normalizeStructTag3 } from "@mysten/sui.js/utils";
|
|
1641
1642
|
var getSpools = async (query, stakeMarketCoinNames) => {
|
|
1642
1643
|
stakeMarketCoinNames = stakeMarketCoinNames || [...SUPPORT_SPOOLS];
|
|
1643
1644
|
const stakeCoinNames = stakeMarketCoinNames.map(
|
|
@@ -1793,34 +1794,34 @@ var getStakeAccounts = async (query, ownerAddress) => {
|
|
|
1793
1794
|
const index = Number(fields.index);
|
|
1794
1795
|
const points = Number(fields.points);
|
|
1795
1796
|
const totalPoints = Number(fields.total_points);
|
|
1796
|
-
if (
|
|
1797
|
+
if (normalizeStructTag3(type) === stakeMarketCoinTypes.ssui) {
|
|
1797
1798
|
stakeAccounts.ssui.push({
|
|
1798
1799
|
id,
|
|
1799
|
-
type,
|
|
1800
|
+
type: normalizeStructTag3(type),
|
|
1800
1801
|
stakePoolId,
|
|
1801
|
-
stakeType,
|
|
1802
|
+
stakeType: normalizeStructTag3(stakeType),
|
|
1802
1803
|
staked,
|
|
1803
1804
|
index,
|
|
1804
1805
|
points,
|
|
1805
1806
|
totalPoints
|
|
1806
1807
|
});
|
|
1807
|
-
} else if (
|
|
1808
|
+
} else if (normalizeStructTag3(type) === stakeMarketCoinTypes.susdc) {
|
|
1808
1809
|
stakeAccounts.susdc.push({
|
|
1809
1810
|
id,
|
|
1810
|
-
type,
|
|
1811
|
+
type: normalizeStructTag3(type),
|
|
1811
1812
|
stakePoolId,
|
|
1812
|
-
stakeType,
|
|
1813
|
+
stakeType: normalizeStructTag3(stakeType),
|
|
1813
1814
|
staked,
|
|
1814
1815
|
index,
|
|
1815
1816
|
points,
|
|
1816
1817
|
totalPoints
|
|
1817
1818
|
});
|
|
1818
|
-
} else if (
|
|
1819
|
+
} else if (normalizeStructTag3(type) === stakeMarketCoinTypes.susdt) {
|
|
1819
1820
|
stakeAccounts.susdt.push({
|
|
1820
1821
|
id,
|
|
1821
|
-
type,
|
|
1822
|
+
type: normalizeStructTag3(type),
|
|
1822
1823
|
stakePoolId,
|
|
1823
|
-
stakeType,
|
|
1824
|
+
stakeType: normalizeStructTag3(stakeType),
|
|
1824
1825
|
staked,
|
|
1825
1826
|
index,
|
|
1826
1827
|
points,
|
|
@@ -1859,13 +1860,13 @@ var getStakePool = async (query, marketCoinName) => {
|
|
|
1859
1860
|
const lastUpdate = Number(fields.last_update);
|
|
1860
1861
|
stakePool = {
|
|
1861
1862
|
id,
|
|
1862
|
-
type,
|
|
1863
|
+
type: normalizeStructTag3(type),
|
|
1863
1864
|
maxPoint,
|
|
1864
1865
|
distributedPoint,
|
|
1865
1866
|
pointPerPeriod,
|
|
1866
1867
|
period,
|
|
1867
1868
|
maxStake,
|
|
1868
|
-
stakeType,
|
|
1869
|
+
stakeType: normalizeStructTag3(stakeType),
|
|
1869
1870
|
totalStaked,
|
|
1870
1871
|
index,
|
|
1871
1872
|
createdAt,
|
|
@@ -1900,7 +1901,7 @@ var getStakeRewardPool = async (query, marketCoinName) => {
|
|
|
1900
1901
|
const claimedRewards = Number(fields.claimed_rewards);
|
|
1901
1902
|
stakeRewardPool = {
|
|
1902
1903
|
id,
|
|
1903
|
-
type,
|
|
1904
|
+
type: normalizeStructTag3(type),
|
|
1904
1905
|
stakePoolId,
|
|
1905
1906
|
ratioNumerator,
|
|
1906
1907
|
ratioDenominator,
|
|
@@ -1913,6 +1914,7 @@ var getStakeRewardPool = async (query, marketCoinName) => {
|
|
|
1913
1914
|
};
|
|
1914
1915
|
|
|
1915
1916
|
// src/queries/borrowIncentiveQuery.ts
|
|
1917
|
+
import { normalizeStructTag as normalizeStructTag4 } from "@mysten/sui.js/utils";
|
|
1916
1918
|
import { SuiTxBlock as SuiKitTxBlock2 } from "@scallop-io/sui-kit";
|
|
1917
1919
|
var queryBorrowIncentivePools = async (query, borrowIncentiveCoinNames) => {
|
|
1918
1920
|
borrowIncentiveCoinNames = borrowIncentiveCoinNames || [
|
|
@@ -1931,7 +1933,7 @@ var queryBorrowIncentivePools = async (query, borrowIncentiveCoinNames) => {
|
|
|
1931
1933
|
const rewardCoinType = parsedBorrowIncentiveRewardPoolData.rewardType;
|
|
1932
1934
|
const borrowIncentivePools = {};
|
|
1933
1935
|
for (const pool of borrowIncentivePoolsQueryData.incentive_pools) {
|
|
1934
|
-
const coinType =
|
|
1936
|
+
const coinType = normalizeStructTag4(pool.pool_type.name);
|
|
1935
1937
|
const coinName = query.utils.parseCoinNameFromType(coinType);
|
|
1936
1938
|
const rewardCoinName = query.utils.parseCoinNameFromType(rewardCoinType);
|
|
1937
1939
|
if (!borrowIncentiveCoinNames.includes(coinName)) {
|
|
@@ -2129,15 +2131,19 @@ var getLending = async (query, poolCoinName, ownerAddress, marketPool, spool, st
|
|
|
2129
2131
|
availableUnstakeAmount = availableUnstakeAmount.plus(
|
|
2130
2132
|
accountStakedMarketCoinAmount
|
|
2131
2133
|
);
|
|
2132
|
-
availableUnstakeCoin = availableUnstakeAmount.shiftedBy(
|
|
2134
|
+
availableUnstakeCoin = availableUnstakeAmount.shiftedBy(
|
|
2135
|
+
-1 * spool.coinDecimal
|
|
2136
|
+
);
|
|
2133
2137
|
const baseIndexRate = 1e9;
|
|
2134
2138
|
const increasedPointRate = spool?.currentPointIndex ? BigNumber3(spool.currentPointIndex - stakeAccount.index).dividedBy(
|
|
2135
2139
|
baseIndexRate
|
|
2136
2140
|
) : 1;
|
|
2137
2141
|
availableClaimAmount = availableClaimAmount.plus(
|
|
2138
|
-
|
|
2142
|
+
accountStakedMarketCoinAmount.multipliedBy(increasedPointRate).plus(stakeAccount.points).multipliedBy(spool.exchangeRateNumerator).dividedBy(spool.exchangeRateDenominator)
|
|
2143
|
+
);
|
|
2144
|
+
availableClaimCoin = availableClaimAmount.shiftedBy(
|
|
2145
|
+
-1 * spool.rewardCoinDecimal
|
|
2139
2146
|
);
|
|
2140
|
-
availableClaimCoin = availableClaimAmount.shiftedBy(-1 * coinDecimal);
|
|
2141
2147
|
}
|
|
2142
2148
|
}
|
|
2143
2149
|
const suppliedAmount = BigNumber3(marketCoinAmount).multipliedBy(
|
|
@@ -2222,10 +2228,13 @@ var getObligationAccount = async (query, obligationId, ownerAddress, market, coi
|
|
|
2222
2228
|
])
|
|
2223
2229
|
];
|
|
2224
2230
|
const obligationQuery = await query.queryObligation(obligationId);
|
|
2231
|
+
const borrowIncentivePools = await query.getBorrowIncentivePools();
|
|
2232
|
+
const borrowIncentiveAccounts = await query.getBorrowIncentiveAccounts(obligationId);
|
|
2225
2233
|
coinPrices = coinPrices || await query.utils.getCoinPrices(assetCoinNames);
|
|
2226
2234
|
coinAmounts = coinAmounts || await query.getCoinAmounts(assetCoinNames, ownerAddress);
|
|
2227
2235
|
const collaterals = {};
|
|
2228
2236
|
const debts = {};
|
|
2237
|
+
const borrowIncentives = {};
|
|
2229
2238
|
let totalDepositedPools = 0;
|
|
2230
2239
|
let totalDepositedValue = BigNumber3(0);
|
|
2231
2240
|
let totalBorrowCapacityValue = BigNumber3(0);
|
|
@@ -2327,6 +2336,41 @@ var getObligationAccount = async (query, obligationId, ownerAddress, market, coi
|
|
|
2327
2336
|
};
|
|
2328
2337
|
}
|
|
2329
2338
|
}
|
|
2339
|
+
for (const [poolCoinName, borrowIncentiveAccount] of Object.entries(
|
|
2340
|
+
borrowIncentiveAccounts
|
|
2341
|
+
)) {
|
|
2342
|
+
const coinName = poolCoinName;
|
|
2343
|
+
const borrowIncentivePool = borrowIncentivePools[coinName];
|
|
2344
|
+
let availableClaimAmount = BigNumber3(0);
|
|
2345
|
+
let availableClaimCoin = BigNumber3(0);
|
|
2346
|
+
if (borrowIncentivePool) {
|
|
2347
|
+
const accountBorrowedAmount = BigNumber3(borrowIncentiveAccount.amount);
|
|
2348
|
+
const baseIndexRate = 1e9;
|
|
2349
|
+
const increasedPointRate = borrowIncentivePool.currentPointIndex ? BigNumber3(
|
|
2350
|
+
borrowIncentivePool.currentPointIndex - borrowIncentiveAccount.index
|
|
2351
|
+
).dividedBy(baseIndexRate) : 1;
|
|
2352
|
+
availableClaimAmount = availableClaimAmount.plus(
|
|
2353
|
+
accountBorrowedAmount.multipliedBy(increasedPointRate).plus(borrowIncentiveAccount.points).multipliedBy(borrowIncentivePool.exchangeRateNumerator).dividedBy(borrowIncentivePool.exchangeRateDenominator)
|
|
2354
|
+
);
|
|
2355
|
+
availableClaimCoin = availableClaimAmount.shiftedBy(
|
|
2356
|
+
-1 * borrowIncentivePool.rewardCoinDecimal
|
|
2357
|
+
);
|
|
2358
|
+
if (availableClaimAmount.isGreaterThan(0)) {
|
|
2359
|
+
borrowIncentives[coinName] = {
|
|
2360
|
+
coinName: borrowIncentivePool.coinName,
|
|
2361
|
+
coinType: borrowIncentivePool.coinType,
|
|
2362
|
+
rewardCoinType: borrowIncentivePool.rewardCoinType,
|
|
2363
|
+
symbol: borrowIncentivePool.symbol,
|
|
2364
|
+
coinDecimal: borrowIncentivePool.coinDecimal,
|
|
2365
|
+
rewardCoinDecimal: borrowIncentivePool.rewardCoinDecimal,
|
|
2366
|
+
coinPrice: borrowIncentivePool.coinPrice,
|
|
2367
|
+
rewardCoinPrice: borrowIncentivePool.rewardCoinPrice,
|
|
2368
|
+
availableClaimAmount: availableClaimAmount.toNumber(),
|
|
2369
|
+
availableClaimCoin: availableClaimCoin.toNumber()
|
|
2370
|
+
};
|
|
2371
|
+
}
|
|
2372
|
+
}
|
|
2373
|
+
}
|
|
2330
2374
|
let riskLevel = totalRequiredCollateralValue.isZero() && totalBorrowedValueWithWeight.isZero() ? BigNumber3(0) : totalBorrowedValueWithWeight.dividedBy(totalRequiredCollateralValue);
|
|
2331
2375
|
riskLevel = riskLevel.isFinite() ? riskLevel.isLessThan(1) ? riskLevel : BigNumber3(1) : BigNumber3(1);
|
|
2332
2376
|
const accountBalanceValue = totalDepositedValue.minus(totalBorrowedValue).isGreaterThan(0) ? totalDepositedValue.minus(totalBorrowedValue) : BigNumber3(0);
|
|
@@ -2355,7 +2399,8 @@ var getObligationAccount = async (query, obligationId, ownerAddress, market, coi
|
|
|
2355
2399
|
totalDepositedPools,
|
|
2356
2400
|
totalBorrowedPools,
|
|
2357
2401
|
collaterals,
|
|
2358
|
-
debts
|
|
2402
|
+
debts,
|
|
2403
|
+
borrowIncentives
|
|
2359
2404
|
};
|
|
2360
2405
|
for (const [collateralCoinName, obligationCollateral] of Object.entries(
|
|
2361
2406
|
obligationAccount.collaterals
|
|
@@ -2371,10 +2416,10 @@ var getObligationAccount = async (query, obligationId, ownerAddress, market, coi
|
|
|
2371
2416
|
obligationCollateral.availableWithdrawCoin = availableWithdrawAmount.shiftedBy(-1 * obligationCollateral.coinDecimal).toNumber();
|
|
2372
2417
|
}
|
|
2373
2418
|
}
|
|
2374
|
-
for (const [
|
|
2419
|
+
for (const [poolCoinName, obligationDebt] of Object.entries(
|
|
2375
2420
|
obligationAccount.debts
|
|
2376
2421
|
)) {
|
|
2377
|
-
const marketPool = market.pools[
|
|
2422
|
+
const marketPool = market.pools[poolCoinName];
|
|
2378
2423
|
if (marketPool) {
|
|
2379
2424
|
const availableRepayAmount = BigNumber3(
|
|
2380
2425
|
obligationDebt.availableRepayAmount
|
|
@@ -2829,7 +2874,7 @@ var ScallopUtils = class {
|
|
|
2829
2874
|
throw Error(`Coin ${coinName} is not supported`);
|
|
2830
2875
|
}
|
|
2831
2876
|
if (coinName === "sui")
|
|
2832
|
-
return
|
|
2877
|
+
return normalizeStructTag5(`${coinPackageId}::sui::SUI`);
|
|
2833
2878
|
const wormHolePckageIds = [
|
|
2834
2879
|
this._address.get("core.coins.usdc.id") ?? wormholeCoinIds.usdc,
|
|
2835
2880
|
this._address.get("core.coins.usdt.id") ?? wormholeCoinIds.usdt,
|
|
@@ -2861,7 +2906,7 @@ var ScallopUtils = class {
|
|
|
2861
2906
|
return `${PROTOCOL_OBJECT_ID}::reserve::MarketCoin<${coinType}>`;
|
|
2862
2907
|
}
|
|
2863
2908
|
parseCoinNameFromType(coinType) {
|
|
2864
|
-
coinType =
|
|
2909
|
+
coinType = normalizeStructTag5(coinType);
|
|
2865
2910
|
const coinTypeRegex = new RegExp(`((0x[^:]+::[^:]+::[^<>]+))(?![^<>]*<)`);
|
|
2866
2911
|
const coinTypeMatch = coinType.match(coinTypeRegex);
|
|
2867
2912
|
const isMarketCoinType = coinType.includes("reserve::MarketCoin");
|