@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.js
CHANGED
|
@@ -1618,13 +1618,14 @@ var calculateMarketPoolData = (utils, parsedMarketPoolData) => {
|
|
|
1618
1618
|
};
|
|
1619
1619
|
};
|
|
1620
1620
|
var parseOriginMarketCollateralData = (originMarketCollateralData) => {
|
|
1621
|
+
const divisor = 2 ** 32;
|
|
1621
1622
|
return {
|
|
1622
1623
|
coinType: (0, import_utils.normalizeStructTag)(originMarketCollateralData.type.name),
|
|
1623
|
-
collateralFactor: Number(originMarketCollateralData.collateralFactor.value) /
|
|
1624
|
-
liquidationFactor: Number(originMarketCollateralData.liquidationFactor.value) /
|
|
1625
|
-
liquidationDiscount: Number(originMarketCollateralData.liquidationDiscount.value) /
|
|
1626
|
-
liquidationPanelty: Number(originMarketCollateralData.liquidationPanelty.value) /
|
|
1627
|
-
liquidationReserveFactor: Number(originMarketCollateralData.liquidationReserveFactor.value) /
|
|
1624
|
+
collateralFactor: Number(originMarketCollateralData.collateralFactor.value) / divisor,
|
|
1625
|
+
liquidationFactor: Number(originMarketCollateralData.liquidationFactor.value) / divisor,
|
|
1626
|
+
liquidationDiscount: Number(originMarketCollateralData.liquidationDiscount.value) / divisor,
|
|
1627
|
+
liquidationPanelty: Number(originMarketCollateralData.liquidationPanelty.value) / divisor,
|
|
1628
|
+
liquidationReserveFactor: Number(originMarketCollateralData.liquidationReserveFactor.value) / divisor,
|
|
1628
1629
|
maxCollateralAmount: Number(originMarketCollateralData.maxCollateralAmount),
|
|
1629
1630
|
totalCollateralAmount: Number(
|
|
1630
1631
|
originMarketCollateralData.totalCollateralAmount
|
|
@@ -1966,15 +1967,6 @@ var findClosestUnlockRound = (unlockAtInSecondTimestamp) => {
|
|
|
1966
1967
|
// src/queries/coreQuery.ts
|
|
1967
1968
|
var import_bignumber2 = __toESM(require("bignumber.js"));
|
|
1968
1969
|
var queryMarket = async (query, indexer = false) => {
|
|
1969
|
-
const packageId = query.address.get("core.packages.query.id");
|
|
1970
|
-
const marketId = query.address.get("core.market");
|
|
1971
|
-
const queryTarget = `${packageId}::market_query::market_data`;
|
|
1972
|
-
const args = [marketId];
|
|
1973
|
-
const queryResult = await query.cache.queryInspectTxn(
|
|
1974
|
-
{ queryTarget, args }
|
|
1975
|
-
// txBlock
|
|
1976
|
-
);
|
|
1977
|
-
const marketData = queryResult.events[0].parsedJson;
|
|
1978
1970
|
const coinPrices = await query.utils.getCoinPrices();
|
|
1979
1971
|
const pools = {};
|
|
1980
1972
|
const collaterals = {};
|
|
@@ -1995,6 +1987,12 @@ var queryMarket = async (query, indexer = false) => {
|
|
|
1995
1987
|
collaterals: marketIndexer.collaterals
|
|
1996
1988
|
};
|
|
1997
1989
|
}
|
|
1990
|
+
const packageId = query.address.get("core.packages.query.id");
|
|
1991
|
+
const marketId = query.address.get("core.market");
|
|
1992
|
+
const queryTarget = `${packageId}::market_query::market_data`;
|
|
1993
|
+
const args = [marketId];
|
|
1994
|
+
const queryResult = await query.cache.queryInspectTxn({ queryTarget, args });
|
|
1995
|
+
const marketData = queryResult.events[0].parsedJson;
|
|
1998
1996
|
for (const pool of marketData.pools) {
|
|
1999
1997
|
const coinType = (0, import_utils2.normalizeStructTag)(pool.type.name);
|
|
2000
1998
|
const poolCoinName = query.utils.parseCoinNameFromType(coinType);
|
|
@@ -2109,18 +2107,20 @@ var getMarketPools = async (query, poolCoinNames, indexer = false) => {
|
|
|
2109
2107
|
}
|
|
2110
2108
|
return marketPools;
|
|
2111
2109
|
}
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
|
|
2120
|
-
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
|
|
2110
|
+
Promise.allSettled(
|
|
2111
|
+
poolCoinNames.map(async (poolCoinName) => {
|
|
2112
|
+
const marketPool = await getMarketPool(
|
|
2113
|
+
query,
|
|
2114
|
+
poolCoinName,
|
|
2115
|
+
indexer,
|
|
2116
|
+
marketObjectResponse.data,
|
|
2117
|
+
coinPrices?.[poolCoinName]
|
|
2118
|
+
);
|
|
2119
|
+
if (marketPool) {
|
|
2120
|
+
marketPools[poolCoinName] = marketPool;
|
|
2121
|
+
}
|
|
2122
|
+
})
|
|
2123
|
+
);
|
|
2124
2124
|
return marketPools;
|
|
2125
2125
|
};
|
|
2126
2126
|
var getMarketPool = async (query, poolCoinName, indexer = false, marketObject, coinPrice) => {
|
|
@@ -2258,10 +2258,12 @@ var getMarketPool = async (query, poolCoinName, indexer = false, marketObject, c
|
|
|
2258
2258
|
var getMarketCollaterals = async (query, collateralCoinNames, indexer = false) => {
|
|
2259
2259
|
collateralCoinNames = collateralCoinNames || [...SUPPORT_COLLATERALS];
|
|
2260
2260
|
const marketId = query.address.get("core.market");
|
|
2261
|
-
const marketObjectResponse = await
|
|
2262
|
-
|
|
2263
|
-
|
|
2264
|
-
|
|
2261
|
+
const [marketObjectResponse, coinPrices] = await Promise.all([
|
|
2262
|
+
query.cache.queryGetObject(marketId, {
|
|
2263
|
+
showContent: true
|
|
2264
|
+
}),
|
|
2265
|
+
query.utils.getCoinPrices(collateralCoinNames ?? [])
|
|
2266
|
+
]);
|
|
2265
2267
|
const marketCollaterals = {};
|
|
2266
2268
|
if (indexer) {
|
|
2267
2269
|
const marketCollateralsIndexer = await query.indexer.getMarketCollaterals();
|
|
@@ -2276,29 +2278,23 @@ var getMarketCollaterals = async (query, collateralCoinNames, indexer = false) =
|
|
|
2276
2278
|
}
|
|
2277
2279
|
return marketCollaterals;
|
|
2278
2280
|
}
|
|
2279
|
-
|
|
2280
|
-
|
|
2281
|
-
|
|
2282
|
-
|
|
2283
|
-
|
|
2284
|
-
|
|
2285
|
-
|
|
2286
|
-
|
|
2287
|
-
|
|
2288
|
-
|
|
2289
|
-
|
|
2290
|
-
|
|
2281
|
+
await Promise.allSettled(
|
|
2282
|
+
collateralCoinNames.map(async (collateralCoinName) => {
|
|
2283
|
+
const marketCollateral = await getMarketCollateral(
|
|
2284
|
+
query,
|
|
2285
|
+
collateralCoinName,
|
|
2286
|
+
indexer,
|
|
2287
|
+
marketObjectResponse.data,
|
|
2288
|
+
coinPrices?.[collateralCoinName]
|
|
2289
|
+
);
|
|
2290
|
+
if (marketCollateral) {
|
|
2291
|
+
marketCollaterals[collateralCoinName] = marketCollateral;
|
|
2292
|
+
}
|
|
2293
|
+
})
|
|
2294
|
+
);
|
|
2291
2295
|
return marketCollaterals;
|
|
2292
2296
|
};
|
|
2293
2297
|
var getMarketCollateral = async (query, collateralCoinName, indexer = false, marketObject, coinPrice) => {
|
|
2294
|
-
const marketId = query.address.get("core.market");
|
|
2295
|
-
marketObject = marketObject || (await query.cache.queryGetObject(marketId, {
|
|
2296
|
-
showContent: true
|
|
2297
|
-
})).data;
|
|
2298
|
-
coinPrice = coinPrice || (await query.utils.getCoinPrices([collateralCoinName]))?.[collateralCoinName];
|
|
2299
|
-
let marketCollateral;
|
|
2300
|
-
let riskModel;
|
|
2301
|
-
let collateralStat;
|
|
2302
2298
|
if (indexer) {
|
|
2303
2299
|
const marketCollateralIndexer = await query.indexer.getMarketCollateral(collateralCoinName);
|
|
2304
2300
|
marketCollateralIndexer.coinPrice = coinPrice || marketCollateralIndexer.coinPrice;
|
|
@@ -2307,6 +2303,14 @@ var getMarketCollateral = async (query, collateralCoinName, indexer = false, mar
|
|
|
2307
2303
|
);
|
|
2308
2304
|
return marketCollateralIndexer;
|
|
2309
2305
|
}
|
|
2306
|
+
let marketCollateral;
|
|
2307
|
+
let riskModel;
|
|
2308
|
+
let collateralStat;
|
|
2309
|
+
const marketId = query.address.get("core.market");
|
|
2310
|
+
marketObject = marketObject || (await query.cache.queryGetObject(marketId, {
|
|
2311
|
+
showContent: true
|
|
2312
|
+
})).data;
|
|
2313
|
+
coinPrice = coinPrice || (await query.utils.getCoinPrices([collateralCoinName]))?.[collateralCoinName];
|
|
2310
2314
|
if (marketObject) {
|
|
2311
2315
|
if (marketObject.content && "fields" in marketObject.content) {
|
|
2312
2316
|
const fields = marketObject.content.fields;
|
|
@@ -2401,15 +2405,17 @@ var getObligations = async (query, ownerAddress) => {
|
|
|
2401
2405
|
const keyObjectIds = keyObjectsResponse.map((ref) => ref?.data?.objectId).filter((id) => id !== void 0);
|
|
2402
2406
|
const keyObjects = await query.cache.queryGetObjects(keyObjectIds);
|
|
2403
2407
|
const obligations = [];
|
|
2404
|
-
|
|
2405
|
-
|
|
2406
|
-
|
|
2407
|
-
|
|
2408
|
-
|
|
2409
|
-
|
|
2410
|
-
|
|
2411
|
-
|
|
2412
|
-
|
|
2408
|
+
await Promise.allSettled(
|
|
2409
|
+
keyObjects.map(async (keyObject) => {
|
|
2410
|
+
const keyId = keyObject.objectId;
|
|
2411
|
+
if (keyObject.content && "fields" in keyObject.content) {
|
|
2412
|
+
const fields = keyObject.content.fields;
|
|
2413
|
+
const obligationId = String(fields.ownership.fields.of);
|
|
2414
|
+
const locked = await getObligationLocked(query, obligationId);
|
|
2415
|
+
obligations.push({ id: obligationId, keyId, locked });
|
|
2416
|
+
}
|
|
2417
|
+
})
|
|
2418
|
+
);
|
|
2413
2419
|
return obligations;
|
|
2414
2420
|
};
|
|
2415
2421
|
var getObligationLocked = async (query, obligationId) => {
|
|
@@ -2863,12 +2869,6 @@ var queryBorrowIncentivePools = async (query, borrowIncentiveCoinNames, indexer
|
|
|
2863
2869
|
borrowIncentiveCoinNames = borrowIncentiveCoinNames || [
|
|
2864
2870
|
...SUPPORT_BORROW_INCENTIVE_POOLS
|
|
2865
2871
|
];
|
|
2866
|
-
const queryPkgId = query.address.get("borrowIncentive.query");
|
|
2867
|
-
const incentivePoolsId = query.address.get("borrowIncentive.incentivePools");
|
|
2868
|
-
const queryTarget = `${queryPkgId}::incentive_pools_query::incentive_pools_data`;
|
|
2869
|
-
const args = [incentivePoolsId];
|
|
2870
|
-
const queryResult = await query.cache.queryInspectTxn({ queryTarget, args });
|
|
2871
|
-
const borrowIncentivePoolsQueryData = queryResult.events[0].parsedJson;
|
|
2872
2872
|
const borrowIncentivePools = {};
|
|
2873
2873
|
const coinPrices = await query.utils.getCoinPrices(
|
|
2874
2874
|
[
|
|
@@ -2890,6 +2890,12 @@ var queryBorrowIncentivePools = async (query, borrowIncentiveCoinNames, indexer
|
|
|
2890
2890
|
}
|
|
2891
2891
|
return borrowIncentivePools;
|
|
2892
2892
|
}
|
|
2893
|
+
const queryPkgId = query.address.get("borrowIncentive.query");
|
|
2894
|
+
const incentivePoolsId = query.address.get("borrowIncentive.incentivePools");
|
|
2895
|
+
const queryTarget = `${queryPkgId}::incentive_pools_query::incentive_pools_data`;
|
|
2896
|
+
const args = [incentivePoolsId];
|
|
2897
|
+
const queryResult = await query.cache.queryInspectTxn({ queryTarget, args });
|
|
2898
|
+
const borrowIncentivePoolsQueryData = queryResult.events[0].parsedJson;
|
|
2893
2899
|
for (const pool of borrowIncentivePoolsQueryData.incentive_pools) {
|
|
2894
2900
|
const borrowIncentivePoolPoints = {};
|
|
2895
2901
|
const parsedBorrowIncentivePoolData = parseOriginBorrowIncentivePoolData(pool);
|
|
@@ -3099,34 +3105,42 @@ var getLendings = async (query, poolCoinNames, ownerAddress, indexer = false) =>
|
|
|
3099
3105
|
const stakeMarketCoinNames = marketCoinNames.filter(
|
|
3100
3106
|
(marketCoinName) => SUPPORT_SPOOLS.includes(marketCoinName)
|
|
3101
3107
|
);
|
|
3102
|
-
const
|
|
3103
|
-
|
|
3104
|
-
|
|
3105
|
-
|
|
3106
|
-
|
|
3107
|
-
|
|
3108
|
-
|
|
3109
|
-
|
|
3110
|
-
|
|
3108
|
+
const [
|
|
3109
|
+
marketPools,
|
|
3110
|
+
spools,
|
|
3111
|
+
coinAmounts,
|
|
3112
|
+
marketCoinAmounts,
|
|
3113
|
+
allStakeAccounts,
|
|
3114
|
+
coinPrices
|
|
3115
|
+
] = await Promise.all([
|
|
3116
|
+
query.getMarketPools(poolCoinNames, indexer),
|
|
3117
|
+
query.getSpools(stakeMarketCoinNames, indexer),
|
|
3118
|
+
query.getCoinAmounts(poolCoinNames, ownerAddress),
|
|
3119
|
+
query.getMarketCoinAmounts(marketCoinNames, ownerAddress),
|
|
3120
|
+
query.getAllStakeAccounts(ownerAddress),
|
|
3121
|
+
query.utils.getCoinPrices(poolCoinNames)
|
|
3122
|
+
]);
|
|
3111
3123
|
const lendings = {};
|
|
3112
|
-
|
|
3113
|
-
|
|
3114
|
-
|
|
3115
|
-
|
|
3116
|
-
|
|
3117
|
-
|
|
3118
|
-
|
|
3119
|
-
|
|
3120
|
-
|
|
3121
|
-
|
|
3122
|
-
|
|
3123
|
-
|
|
3124
|
-
|
|
3125
|
-
|
|
3126
|
-
|
|
3127
|
-
|
|
3128
|
-
|
|
3129
|
-
|
|
3124
|
+
await Promise.allSettled(
|
|
3125
|
+
poolCoinNames.map(async (poolCoinName) => {
|
|
3126
|
+
const stakeMarketCoinName = stakeMarketCoinNames.find(
|
|
3127
|
+
(marketCoinName2) => marketCoinName2 === query.utils.parseMarketCoinName(poolCoinName)
|
|
3128
|
+
);
|
|
3129
|
+
const marketCoinName = query.utils.parseMarketCoinName(poolCoinName);
|
|
3130
|
+
lendings[poolCoinName] = await getLending(
|
|
3131
|
+
query,
|
|
3132
|
+
poolCoinName,
|
|
3133
|
+
ownerAddress,
|
|
3134
|
+
indexer,
|
|
3135
|
+
marketPools?.[poolCoinName],
|
|
3136
|
+
stakeMarketCoinName ? spools[stakeMarketCoinName] : void 0,
|
|
3137
|
+
stakeMarketCoinName ? allStakeAccounts[stakeMarketCoinName] : void 0,
|
|
3138
|
+
coinAmounts?.[poolCoinName],
|
|
3139
|
+
marketCoinAmounts?.[marketCoinName],
|
|
3140
|
+
coinPrices?.[poolCoinName] ?? 0
|
|
3141
|
+
);
|
|
3142
|
+
})
|
|
3143
|
+
);
|
|
3130
3144
|
return lendings;
|
|
3131
3145
|
};
|
|
3132
3146
|
var getLending = async (query, poolCoinName, ownerAddress, indexer = false, marketPool, spool, stakeAccounts, coinAmount, marketCoinAmount, coinPrice) => {
|
|
@@ -4242,15 +4256,17 @@ var ScallopQuery = class {
|
|
|
4242
4256
|
async getStakeRewardPools(stakeMarketCoinNames) {
|
|
4243
4257
|
stakeMarketCoinNames = stakeMarketCoinNames ?? [...SUPPORT_SPOOLS];
|
|
4244
4258
|
const stakeRewardPools = {};
|
|
4245
|
-
|
|
4246
|
-
|
|
4247
|
-
|
|
4248
|
-
|
|
4249
|
-
|
|
4250
|
-
|
|
4251
|
-
|
|
4252
|
-
|
|
4253
|
-
|
|
4259
|
+
await Promise.allSettled(
|
|
4260
|
+
stakeMarketCoinNames.map(async (stakeMarketCoinName) => {
|
|
4261
|
+
const stakeRewardPool = await getStakeRewardPool(
|
|
4262
|
+
this,
|
|
4263
|
+
stakeMarketCoinName
|
|
4264
|
+
);
|
|
4265
|
+
if (stakeRewardPool) {
|
|
4266
|
+
stakeRewardPools[stakeMarketCoinName] = stakeRewardPool;
|
|
4267
|
+
}
|
|
4268
|
+
})
|
|
4269
|
+
);
|
|
4254
4270
|
return stakeRewardPools;
|
|
4255
4271
|
}
|
|
4256
4272
|
/**
|