@scallop-io/sui-scallop-sdk 0.46.37 → 0.46.38
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 +117 -101
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +117 -101
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/models/scallopQuery.ts +12 -11
- package/src/queries/borrowIncentiveQuery.ts +9 -8
- package/src/queries/coreQuery.ts +70 -66
- package/src/queries/portfolioQuery.ts +36 -28
- package/src/utils/query.ts +6 -5
package/dist/index.mjs
CHANGED
|
@@ -1545,13 +1545,14 @@ var calculateMarketPoolData = (utils, parsedMarketPoolData) => {
|
|
|
1545
1545
|
};
|
|
1546
1546
|
};
|
|
1547
1547
|
var parseOriginMarketCollateralData = (originMarketCollateralData) => {
|
|
1548
|
+
const divisor = 2 ** 32;
|
|
1548
1549
|
return {
|
|
1549
1550
|
coinType: normalizeStructTag2(originMarketCollateralData.type.name),
|
|
1550
|
-
collateralFactor: Number(originMarketCollateralData.collateralFactor.value) /
|
|
1551
|
-
liquidationFactor: Number(originMarketCollateralData.liquidationFactor.value) /
|
|
1552
|
-
liquidationDiscount: Number(originMarketCollateralData.liquidationDiscount.value) /
|
|
1553
|
-
liquidationPanelty: Number(originMarketCollateralData.liquidationPanelty.value) /
|
|
1554
|
-
liquidationReserveFactor: Number(originMarketCollateralData.liquidationReserveFactor.value) /
|
|
1551
|
+
collateralFactor: Number(originMarketCollateralData.collateralFactor.value) / divisor,
|
|
1552
|
+
liquidationFactor: Number(originMarketCollateralData.liquidationFactor.value) / divisor,
|
|
1553
|
+
liquidationDiscount: Number(originMarketCollateralData.liquidationDiscount.value) / divisor,
|
|
1554
|
+
liquidationPanelty: Number(originMarketCollateralData.liquidationPanelty.value) / divisor,
|
|
1555
|
+
liquidationReserveFactor: Number(originMarketCollateralData.liquidationReserveFactor.value) / divisor,
|
|
1555
1556
|
maxCollateralAmount: Number(originMarketCollateralData.maxCollateralAmount),
|
|
1556
1557
|
totalCollateralAmount: Number(
|
|
1557
1558
|
originMarketCollateralData.totalCollateralAmount
|
|
@@ -1893,15 +1894,6 @@ var findClosestUnlockRound = (unlockAtInSecondTimestamp) => {
|
|
|
1893
1894
|
// src/queries/coreQuery.ts
|
|
1894
1895
|
import BigNumber2 from "bignumber.js";
|
|
1895
1896
|
var queryMarket = async (query, indexer = false) => {
|
|
1896
|
-
const packageId = query.address.get("core.packages.query.id");
|
|
1897
|
-
const marketId = query.address.get("core.market");
|
|
1898
|
-
const queryTarget = `${packageId}::market_query::market_data`;
|
|
1899
|
-
const args = [marketId];
|
|
1900
|
-
const queryResult = await query.cache.queryInspectTxn(
|
|
1901
|
-
{ queryTarget, args }
|
|
1902
|
-
// txBlock
|
|
1903
|
-
);
|
|
1904
|
-
const marketData = queryResult.events[0].parsedJson;
|
|
1905
1897
|
const coinPrices = await query.utils.getCoinPrices();
|
|
1906
1898
|
const pools = {};
|
|
1907
1899
|
const collaterals = {};
|
|
@@ -1922,6 +1914,12 @@ var queryMarket = async (query, indexer = false) => {
|
|
|
1922
1914
|
collaterals: marketIndexer.collaterals
|
|
1923
1915
|
};
|
|
1924
1916
|
}
|
|
1917
|
+
const packageId = query.address.get("core.packages.query.id");
|
|
1918
|
+
const marketId = query.address.get("core.market");
|
|
1919
|
+
const queryTarget = `${packageId}::market_query::market_data`;
|
|
1920
|
+
const args = [marketId];
|
|
1921
|
+
const queryResult = await query.cache.queryInspectTxn({ queryTarget, args });
|
|
1922
|
+
const marketData = queryResult.events[0].parsedJson;
|
|
1925
1923
|
for (const pool of marketData.pools) {
|
|
1926
1924
|
const coinType = normalizeStructTag3(pool.type.name);
|
|
1927
1925
|
const poolCoinName = query.utils.parseCoinNameFromType(coinType);
|
|
@@ -2036,18 +2034,20 @@ var getMarketPools = async (query, poolCoinNames, indexer = false) => {
|
|
|
2036
2034
|
}
|
|
2037
2035
|
return marketPools;
|
|
2038
2036
|
}
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2037
|
+
Promise.allSettled(
|
|
2038
|
+
poolCoinNames.map(async (poolCoinName) => {
|
|
2039
|
+
const marketPool = await getMarketPool(
|
|
2040
|
+
query,
|
|
2041
|
+
poolCoinName,
|
|
2042
|
+
indexer,
|
|
2043
|
+
marketObjectResponse.data,
|
|
2044
|
+
coinPrices?.[poolCoinName]
|
|
2045
|
+
);
|
|
2046
|
+
if (marketPool) {
|
|
2047
|
+
marketPools[poolCoinName] = marketPool;
|
|
2048
|
+
}
|
|
2049
|
+
})
|
|
2050
|
+
);
|
|
2051
2051
|
return marketPools;
|
|
2052
2052
|
};
|
|
2053
2053
|
var getMarketPool = async (query, poolCoinName, indexer = false, marketObject, coinPrice) => {
|
|
@@ -2185,10 +2185,12 @@ var getMarketPool = async (query, poolCoinName, indexer = false, marketObject, c
|
|
|
2185
2185
|
var getMarketCollaterals = async (query, collateralCoinNames, indexer = false) => {
|
|
2186
2186
|
collateralCoinNames = collateralCoinNames || [...SUPPORT_COLLATERALS];
|
|
2187
2187
|
const marketId = query.address.get("core.market");
|
|
2188
|
-
const marketObjectResponse = await
|
|
2189
|
-
|
|
2190
|
-
|
|
2191
|
-
|
|
2188
|
+
const [marketObjectResponse, coinPrices] = await Promise.all([
|
|
2189
|
+
query.cache.queryGetObject(marketId, {
|
|
2190
|
+
showContent: true
|
|
2191
|
+
}),
|
|
2192
|
+
query.utils.getCoinPrices(collateralCoinNames ?? [])
|
|
2193
|
+
]);
|
|
2192
2194
|
const marketCollaterals = {};
|
|
2193
2195
|
if (indexer) {
|
|
2194
2196
|
const marketCollateralsIndexer = await query.indexer.getMarketCollaterals();
|
|
@@ -2203,29 +2205,23 @@ var getMarketCollaterals = async (query, collateralCoinNames, indexer = false) =
|
|
|
2203
2205
|
}
|
|
2204
2206
|
return marketCollaterals;
|
|
2205
2207
|
}
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
|
|
2209
|
-
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
|
|
2208
|
+
await Promise.allSettled(
|
|
2209
|
+
collateralCoinNames.map(async (collateralCoinName) => {
|
|
2210
|
+
const marketCollateral = await getMarketCollateral(
|
|
2211
|
+
query,
|
|
2212
|
+
collateralCoinName,
|
|
2213
|
+
indexer,
|
|
2214
|
+
marketObjectResponse.data,
|
|
2215
|
+
coinPrices?.[collateralCoinName]
|
|
2216
|
+
);
|
|
2217
|
+
if (marketCollateral) {
|
|
2218
|
+
marketCollaterals[collateralCoinName] = marketCollateral;
|
|
2219
|
+
}
|
|
2220
|
+
})
|
|
2221
|
+
);
|
|
2218
2222
|
return marketCollaterals;
|
|
2219
2223
|
};
|
|
2220
2224
|
var getMarketCollateral = async (query, collateralCoinName, indexer = false, marketObject, coinPrice) => {
|
|
2221
|
-
const marketId = query.address.get("core.market");
|
|
2222
|
-
marketObject = marketObject || (await query.cache.queryGetObject(marketId, {
|
|
2223
|
-
showContent: true
|
|
2224
|
-
})).data;
|
|
2225
|
-
coinPrice = coinPrice || (await query.utils.getCoinPrices([collateralCoinName]))?.[collateralCoinName];
|
|
2226
|
-
let marketCollateral;
|
|
2227
|
-
let riskModel;
|
|
2228
|
-
let collateralStat;
|
|
2229
2225
|
if (indexer) {
|
|
2230
2226
|
const marketCollateralIndexer = await query.indexer.getMarketCollateral(collateralCoinName);
|
|
2231
2227
|
marketCollateralIndexer.coinPrice = coinPrice || marketCollateralIndexer.coinPrice;
|
|
@@ -2234,6 +2230,14 @@ var getMarketCollateral = async (query, collateralCoinName, indexer = false, mar
|
|
|
2234
2230
|
);
|
|
2235
2231
|
return marketCollateralIndexer;
|
|
2236
2232
|
}
|
|
2233
|
+
let marketCollateral;
|
|
2234
|
+
let riskModel;
|
|
2235
|
+
let collateralStat;
|
|
2236
|
+
const marketId = query.address.get("core.market");
|
|
2237
|
+
marketObject = marketObject || (await query.cache.queryGetObject(marketId, {
|
|
2238
|
+
showContent: true
|
|
2239
|
+
})).data;
|
|
2240
|
+
coinPrice = coinPrice || (await query.utils.getCoinPrices([collateralCoinName]))?.[collateralCoinName];
|
|
2237
2241
|
if (marketObject) {
|
|
2238
2242
|
if (marketObject.content && "fields" in marketObject.content) {
|
|
2239
2243
|
const fields = marketObject.content.fields;
|
|
@@ -2328,15 +2332,17 @@ var getObligations = async (query, ownerAddress) => {
|
|
|
2328
2332
|
const keyObjectIds = keyObjectsResponse.map((ref) => ref?.data?.objectId).filter((id) => id !== void 0);
|
|
2329
2333
|
const keyObjects = await query.cache.queryGetObjects(keyObjectIds);
|
|
2330
2334
|
const obligations = [];
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
|
|
2334
|
-
|
|
2335
|
-
|
|
2336
|
-
|
|
2337
|
-
|
|
2338
|
-
|
|
2339
|
-
|
|
2335
|
+
await Promise.allSettled(
|
|
2336
|
+
keyObjects.map(async (keyObject) => {
|
|
2337
|
+
const keyId = keyObject.objectId;
|
|
2338
|
+
if (keyObject.content && "fields" in keyObject.content) {
|
|
2339
|
+
const fields = keyObject.content.fields;
|
|
2340
|
+
const obligationId = String(fields.ownership.fields.of);
|
|
2341
|
+
const locked = await getObligationLocked(query, obligationId);
|
|
2342
|
+
obligations.push({ id: obligationId, keyId, locked });
|
|
2343
|
+
}
|
|
2344
|
+
})
|
|
2345
|
+
);
|
|
2340
2346
|
return obligations;
|
|
2341
2347
|
};
|
|
2342
2348
|
var getObligationLocked = async (query, obligationId) => {
|
|
@@ -2790,12 +2796,6 @@ var queryBorrowIncentivePools = async (query, borrowIncentiveCoinNames, indexer
|
|
|
2790
2796
|
borrowIncentiveCoinNames = borrowIncentiveCoinNames || [
|
|
2791
2797
|
...SUPPORT_BORROW_INCENTIVE_POOLS
|
|
2792
2798
|
];
|
|
2793
|
-
const queryPkgId = query.address.get("borrowIncentive.query");
|
|
2794
|
-
const incentivePoolsId = query.address.get("borrowIncentive.incentivePools");
|
|
2795
|
-
const queryTarget = `${queryPkgId}::incentive_pools_query::incentive_pools_data`;
|
|
2796
|
-
const args = [incentivePoolsId];
|
|
2797
|
-
const queryResult = await query.cache.queryInspectTxn({ queryTarget, args });
|
|
2798
|
-
const borrowIncentivePoolsQueryData = queryResult.events[0].parsedJson;
|
|
2799
2799
|
const borrowIncentivePools = {};
|
|
2800
2800
|
const coinPrices = await query.utils.getCoinPrices(
|
|
2801
2801
|
[
|
|
@@ -2817,6 +2817,12 @@ var queryBorrowIncentivePools = async (query, borrowIncentiveCoinNames, indexer
|
|
|
2817
2817
|
}
|
|
2818
2818
|
return borrowIncentivePools;
|
|
2819
2819
|
}
|
|
2820
|
+
const queryPkgId = query.address.get("borrowIncentive.query");
|
|
2821
|
+
const incentivePoolsId = query.address.get("borrowIncentive.incentivePools");
|
|
2822
|
+
const queryTarget = `${queryPkgId}::incentive_pools_query::incentive_pools_data`;
|
|
2823
|
+
const args = [incentivePoolsId];
|
|
2824
|
+
const queryResult = await query.cache.queryInspectTxn({ queryTarget, args });
|
|
2825
|
+
const borrowIncentivePoolsQueryData = queryResult.events[0].parsedJson;
|
|
2820
2826
|
for (const pool of borrowIncentivePoolsQueryData.incentive_pools) {
|
|
2821
2827
|
const borrowIncentivePoolPoints = {};
|
|
2822
2828
|
const parsedBorrowIncentivePoolData = parseOriginBorrowIncentivePoolData(pool);
|
|
@@ -3026,34 +3032,42 @@ var getLendings = async (query, poolCoinNames, ownerAddress, indexer = false) =>
|
|
|
3026
3032
|
const stakeMarketCoinNames = marketCoinNames.filter(
|
|
3027
3033
|
(marketCoinName) => SUPPORT_SPOOLS.includes(marketCoinName)
|
|
3028
3034
|
);
|
|
3029
|
-
const
|
|
3030
|
-
|
|
3031
|
-
|
|
3032
|
-
|
|
3033
|
-
|
|
3034
|
-
|
|
3035
|
-
|
|
3036
|
-
|
|
3037
|
-
|
|
3035
|
+
const [
|
|
3036
|
+
marketPools,
|
|
3037
|
+
spools,
|
|
3038
|
+
coinAmounts,
|
|
3039
|
+
marketCoinAmounts,
|
|
3040
|
+
allStakeAccounts,
|
|
3041
|
+
coinPrices
|
|
3042
|
+
] = await Promise.all([
|
|
3043
|
+
query.getMarketPools(poolCoinNames, indexer),
|
|
3044
|
+
query.getSpools(stakeMarketCoinNames, indexer),
|
|
3045
|
+
query.getCoinAmounts(poolCoinNames, ownerAddress),
|
|
3046
|
+
query.getMarketCoinAmounts(marketCoinNames, ownerAddress),
|
|
3047
|
+
query.getAllStakeAccounts(ownerAddress),
|
|
3048
|
+
query.utils.getCoinPrices(poolCoinNames)
|
|
3049
|
+
]);
|
|
3038
3050
|
const lendings = {};
|
|
3039
|
-
|
|
3040
|
-
|
|
3041
|
-
|
|
3042
|
-
|
|
3043
|
-
|
|
3044
|
-
|
|
3045
|
-
|
|
3046
|
-
|
|
3047
|
-
|
|
3048
|
-
|
|
3049
|
-
|
|
3050
|
-
|
|
3051
|
-
|
|
3052
|
-
|
|
3053
|
-
|
|
3054
|
-
|
|
3055
|
-
|
|
3056
|
-
|
|
3051
|
+
await Promise.allSettled(
|
|
3052
|
+
poolCoinNames.map(async (poolCoinName) => {
|
|
3053
|
+
const stakeMarketCoinName = stakeMarketCoinNames.find(
|
|
3054
|
+
(marketCoinName2) => marketCoinName2 === query.utils.parseMarketCoinName(poolCoinName)
|
|
3055
|
+
);
|
|
3056
|
+
const marketCoinName = query.utils.parseMarketCoinName(poolCoinName);
|
|
3057
|
+
lendings[poolCoinName] = await getLending(
|
|
3058
|
+
query,
|
|
3059
|
+
poolCoinName,
|
|
3060
|
+
ownerAddress,
|
|
3061
|
+
indexer,
|
|
3062
|
+
marketPools?.[poolCoinName],
|
|
3063
|
+
stakeMarketCoinName ? spools[stakeMarketCoinName] : void 0,
|
|
3064
|
+
stakeMarketCoinName ? allStakeAccounts[stakeMarketCoinName] : void 0,
|
|
3065
|
+
coinAmounts?.[poolCoinName],
|
|
3066
|
+
marketCoinAmounts?.[marketCoinName],
|
|
3067
|
+
coinPrices?.[poolCoinName] ?? 0
|
|
3068
|
+
);
|
|
3069
|
+
})
|
|
3070
|
+
);
|
|
3057
3071
|
return lendings;
|
|
3058
3072
|
};
|
|
3059
3073
|
var getLending = async (query, poolCoinName, ownerAddress, indexer = false, marketPool, spool, stakeAccounts, coinAmount, marketCoinAmount, coinPrice) => {
|
|
@@ -4169,15 +4183,17 @@ var ScallopQuery = class {
|
|
|
4169
4183
|
async getStakeRewardPools(stakeMarketCoinNames) {
|
|
4170
4184
|
stakeMarketCoinNames = stakeMarketCoinNames ?? [...SUPPORT_SPOOLS];
|
|
4171
4185
|
const stakeRewardPools = {};
|
|
4172
|
-
|
|
4173
|
-
|
|
4174
|
-
|
|
4175
|
-
|
|
4176
|
-
|
|
4177
|
-
|
|
4178
|
-
|
|
4179
|
-
|
|
4180
|
-
|
|
4186
|
+
await Promise.allSettled(
|
|
4187
|
+
stakeMarketCoinNames.map(async (stakeMarketCoinName) => {
|
|
4188
|
+
const stakeRewardPool = await getStakeRewardPool(
|
|
4189
|
+
this,
|
|
4190
|
+
stakeMarketCoinName
|
|
4191
|
+
);
|
|
4192
|
+
if (stakeRewardPool) {
|
|
4193
|
+
stakeRewardPools[stakeMarketCoinName] = stakeRewardPool;
|
|
4194
|
+
}
|
|
4195
|
+
})
|
|
4196
|
+
);
|
|
4181
4197
|
return stakeRewardPools;
|
|
4182
4198
|
}
|
|
4183
4199
|
/**
|