@scallop-io/sui-scallop-sdk 0.46.37 → 0.46.39
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 +124 -108
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +124 -108
- 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 +84 -80
- package/src/queries/portfolioQuery.ts +36 -28
- package/src/queries/vescaQuery.ts +7 -9
- package/src/utils/query.ts +6 -5
package/package.json
CHANGED
|
@@ -396,17 +396,18 @@ export class ScallopQuery {
|
|
|
396
396
|
) {
|
|
397
397
|
stakeMarketCoinNames = stakeMarketCoinNames ?? [...SUPPORT_SPOOLS];
|
|
398
398
|
const stakeRewardPools: StakeRewardPools = {};
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
399
|
+
await Promise.allSettled(
|
|
400
|
+
stakeMarketCoinNames.map(async (stakeMarketCoinName) => {
|
|
401
|
+
const stakeRewardPool = await getStakeRewardPool(
|
|
402
|
+
this,
|
|
403
|
+
stakeMarketCoinName
|
|
404
|
+
);
|
|
405
|
+
|
|
406
|
+
if (stakeRewardPool) {
|
|
407
|
+
stakeRewardPools[stakeMarketCoinName] = stakeRewardPool;
|
|
408
|
+
}
|
|
409
|
+
})
|
|
410
|
+
);
|
|
410
411
|
return stakeRewardPools;
|
|
411
412
|
}
|
|
412
413
|
|
|
@@ -37,14 +37,6 @@ export const queryBorrowIncentivePools = async (
|
|
|
37
37
|
borrowIncentiveCoinNames = borrowIncentiveCoinNames || [
|
|
38
38
|
...SUPPORT_BORROW_INCENTIVE_POOLS,
|
|
39
39
|
];
|
|
40
|
-
const queryPkgId = query.address.get('borrowIncentive.query');
|
|
41
|
-
const incentivePoolsId = query.address.get('borrowIncentive.incentivePools');
|
|
42
|
-
|
|
43
|
-
const queryTarget = `${queryPkgId}::incentive_pools_query::incentive_pools_data`;
|
|
44
|
-
const args = [incentivePoolsId];
|
|
45
|
-
const queryResult = await query.cache.queryInspectTxn({ queryTarget, args });
|
|
46
|
-
const borrowIncentivePoolsQueryData = queryResult.events[0]
|
|
47
|
-
.parsedJson as BorrowIncentivePoolsQueryInterface;
|
|
48
40
|
|
|
49
41
|
const borrowIncentivePools: BorrowIncentivePools = {};
|
|
50
42
|
|
|
@@ -75,6 +67,15 @@ export const queryBorrowIncentivePools = async (
|
|
|
75
67
|
return borrowIncentivePools;
|
|
76
68
|
}
|
|
77
69
|
|
|
70
|
+
const queryPkgId = query.address.get('borrowIncentive.query');
|
|
71
|
+
const incentivePoolsId = query.address.get('borrowIncentive.incentivePools');
|
|
72
|
+
|
|
73
|
+
const queryTarget = `${queryPkgId}::incentive_pools_query::incentive_pools_data`;
|
|
74
|
+
const args = [incentivePoolsId];
|
|
75
|
+
const queryResult = await query.cache.queryInspectTxn({ queryTarget, args });
|
|
76
|
+
const borrowIncentivePoolsQueryData = queryResult.events[0]
|
|
77
|
+
.parsedJson as BorrowIncentivePoolsQueryInterface;
|
|
78
|
+
|
|
78
79
|
for (const pool of borrowIncentivePoolsQueryData.incentive_pools) {
|
|
79
80
|
const borrowIncentivePoolPoints: OptionalKeys<
|
|
80
81
|
Record<SupportBorrowIncentiveRewardCoins, BorrowIncentivePoolPoints>
|
package/src/queries/coreQuery.ts
CHANGED
|
@@ -50,18 +50,6 @@ export const queryMarket = async (
|
|
|
50
50
|
query: ScallopQuery,
|
|
51
51
|
indexer: boolean = false
|
|
52
52
|
) => {
|
|
53
|
-
const packageId = query.address.get('core.packages.query.id');
|
|
54
|
-
const marketId = query.address.get('core.market');
|
|
55
|
-
const queryTarget = `${packageId}::market_query::market_data`;
|
|
56
|
-
const args = [marketId];
|
|
57
|
-
|
|
58
|
-
// const txBlock = new SuiKitTxBlock();
|
|
59
|
-
// txBlock.moveCall(queryTarget, args);
|
|
60
|
-
const queryResult = await query.cache.queryInspectTxn(
|
|
61
|
-
{ queryTarget, args }
|
|
62
|
-
// txBlock
|
|
63
|
-
);
|
|
64
|
-
const marketData = queryResult.events[0].parsedJson as MarketQueryInterface;
|
|
65
53
|
const coinPrices = await query.utils.getCoinPrices();
|
|
66
54
|
|
|
67
55
|
const pools: MarketPools = {};
|
|
@@ -86,6 +74,14 @@ export const queryMarket = async (
|
|
|
86
74
|
};
|
|
87
75
|
}
|
|
88
76
|
|
|
77
|
+
const packageId = query.address.get('core.packages.query.id');
|
|
78
|
+
const marketId = query.address.get('core.market');
|
|
79
|
+
const queryTarget = `${packageId}::market_query::market_data`;
|
|
80
|
+
const args = [marketId];
|
|
81
|
+
|
|
82
|
+
const queryResult = await query.cache.queryInspectTxn({ queryTarget, args });
|
|
83
|
+
const marketData = queryResult.events[0].parsedJson as MarketQueryInterface;
|
|
84
|
+
|
|
89
85
|
for (const pool of marketData.pools) {
|
|
90
86
|
const coinType = normalizeStructTag(pool.type.name);
|
|
91
87
|
const poolCoinName =
|
|
@@ -236,19 +232,21 @@ export const getMarketPools = async (
|
|
|
236
232
|
return marketPools;
|
|
237
233
|
}
|
|
238
234
|
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
235
|
+
await Promise.allSettled(
|
|
236
|
+
poolCoinNames.map(async (poolCoinName) => {
|
|
237
|
+
const marketPool = await getMarketPool(
|
|
238
|
+
query,
|
|
239
|
+
poolCoinName,
|
|
240
|
+
indexer,
|
|
241
|
+
marketObjectResponse.data,
|
|
242
|
+
coinPrices?.[poolCoinName]
|
|
243
|
+
);
|
|
247
244
|
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
245
|
+
if (marketPool) {
|
|
246
|
+
marketPools[poolCoinName] = marketPool;
|
|
247
|
+
}
|
|
248
|
+
})
|
|
249
|
+
);
|
|
252
250
|
|
|
253
251
|
return marketPools;
|
|
254
252
|
};
|
|
@@ -270,19 +268,6 @@ export const getMarketPool = async (
|
|
|
270
268
|
marketObject?: SuiObjectData | null,
|
|
271
269
|
coinPrice?: number
|
|
272
270
|
) => {
|
|
273
|
-
const marketId = query.address.get('core.market');
|
|
274
|
-
marketObject =
|
|
275
|
-
marketObject ||
|
|
276
|
-
(
|
|
277
|
-
await query.cache.queryGetObject(marketId, {
|
|
278
|
-
showContent: true,
|
|
279
|
-
})
|
|
280
|
-
).data;
|
|
281
|
-
|
|
282
|
-
coinPrice =
|
|
283
|
-
coinPrice ||
|
|
284
|
-
(await query.utils.getCoinPrices([poolCoinName]))?.[poolCoinName];
|
|
285
|
-
|
|
286
271
|
let marketPool: MarketPool | undefined;
|
|
287
272
|
let balanceSheet: BalanceSheet | undefined;
|
|
288
273
|
let borrowIndex: BorrowIndex | undefined;
|
|
@@ -299,6 +284,19 @@ export const getMarketPool = async (
|
|
|
299
284
|
return marketPoolIndexer;
|
|
300
285
|
}
|
|
301
286
|
|
|
287
|
+
const marketId = query.address.get('core.market');
|
|
288
|
+
marketObject =
|
|
289
|
+
marketObject ||
|
|
290
|
+
(
|
|
291
|
+
await query.cache.queryGetObject(marketId, {
|
|
292
|
+
showContent: true,
|
|
293
|
+
})
|
|
294
|
+
).data;
|
|
295
|
+
|
|
296
|
+
coinPrice =
|
|
297
|
+
coinPrice ||
|
|
298
|
+
(await query.utils.getCoinPrices([poolCoinName]))?.[poolCoinName];
|
|
299
|
+
|
|
302
300
|
if (marketObject) {
|
|
303
301
|
if (marketObject.content && 'fields' in marketObject.content) {
|
|
304
302
|
const fields = marketObject.content.fields as any;
|
|
@@ -475,11 +473,12 @@ export const getMarketCollaterals = async (
|
|
|
475
473
|
) => {
|
|
476
474
|
collateralCoinNames = collateralCoinNames || [...SUPPORT_COLLATERALS];
|
|
477
475
|
const marketId = query.address.get('core.market');
|
|
478
|
-
const marketObjectResponse = await
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
476
|
+
const [marketObjectResponse, coinPrices] = await Promise.all([
|
|
477
|
+
query.cache.queryGetObject(marketId, {
|
|
478
|
+
showContent: true,
|
|
479
|
+
}),
|
|
480
|
+
query.utils.getCoinPrices(collateralCoinNames ?? []),
|
|
481
|
+
]);
|
|
483
482
|
const marketCollaterals: MarketCollaterals = {};
|
|
484
483
|
|
|
485
484
|
if (indexer) {
|
|
@@ -496,19 +495,21 @@ export const getMarketCollaterals = async (
|
|
|
496
495
|
return marketCollaterals;
|
|
497
496
|
}
|
|
498
497
|
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
498
|
+
await Promise.allSettled(
|
|
499
|
+
collateralCoinNames.map(async (collateralCoinName) => {
|
|
500
|
+
const marketCollateral = await getMarketCollateral(
|
|
501
|
+
query,
|
|
502
|
+
collateralCoinName,
|
|
503
|
+
indexer,
|
|
504
|
+
marketObjectResponse.data,
|
|
505
|
+
coinPrices?.[collateralCoinName]
|
|
506
|
+
);
|
|
507
507
|
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
508
|
+
if (marketCollateral) {
|
|
509
|
+
marketCollaterals[collateralCoinName] = marketCollateral;
|
|
510
|
+
}
|
|
511
|
+
})
|
|
512
|
+
);
|
|
512
513
|
|
|
513
514
|
return marketCollaterals;
|
|
514
515
|
};
|
|
@@ -530,6 +531,22 @@ export const getMarketCollateral = async (
|
|
|
530
531
|
marketObject?: SuiObjectData | null,
|
|
531
532
|
coinPrice?: number
|
|
532
533
|
) => {
|
|
534
|
+
if (indexer) {
|
|
535
|
+
const marketCollateralIndexer =
|
|
536
|
+
await query.indexer.getMarketCollateral(collateralCoinName);
|
|
537
|
+
marketCollateralIndexer.coinPrice =
|
|
538
|
+
coinPrice || marketCollateralIndexer.coinPrice;
|
|
539
|
+
marketCollateralIndexer.coinWrappedType = query.utils.getCoinWrappedType(
|
|
540
|
+
marketCollateralIndexer.coinName
|
|
541
|
+
);
|
|
542
|
+
|
|
543
|
+
return marketCollateralIndexer;
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
let marketCollateral: MarketCollateral | undefined;
|
|
547
|
+
let riskModel: RiskModel | undefined;
|
|
548
|
+
let collateralStat: CollateralStat | undefined;
|
|
549
|
+
|
|
533
550
|
const marketId = query.address.get('core.market');
|
|
534
551
|
marketObject =
|
|
535
552
|
marketObject ||
|
|
@@ -545,22 +562,6 @@ export const getMarketCollateral = async (
|
|
|
545
562
|
collateralCoinName
|
|
546
563
|
];
|
|
547
564
|
|
|
548
|
-
let marketCollateral: MarketCollateral | undefined;
|
|
549
|
-
let riskModel: RiskModel | undefined;
|
|
550
|
-
let collateralStat: CollateralStat | undefined;
|
|
551
|
-
|
|
552
|
-
if (indexer) {
|
|
553
|
-
const marketCollateralIndexer =
|
|
554
|
-
await query.indexer.getMarketCollateral(collateralCoinName);
|
|
555
|
-
marketCollateralIndexer.coinPrice =
|
|
556
|
-
coinPrice || marketCollateralIndexer.coinPrice;
|
|
557
|
-
marketCollateralIndexer.coinWrappedType = query.utils.getCoinWrappedType(
|
|
558
|
-
marketCollateralIndexer.coinName
|
|
559
|
-
);
|
|
560
|
-
|
|
561
|
-
return marketCollateralIndexer;
|
|
562
|
-
}
|
|
563
|
-
|
|
564
565
|
if (marketObject) {
|
|
565
566
|
if (marketObject.content && 'fields' in marketObject.content) {
|
|
566
567
|
const fields = marketObject.content.fields as any;
|
|
@@ -698,15 +699,18 @@ export const getObligations = async (
|
|
|
698
699
|
const keyObjects = await query.cache.queryGetObjects(keyObjectIds);
|
|
699
700
|
|
|
700
701
|
const obligations: Obligation[] = [];
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
702
|
+
await Promise.allSettled(
|
|
703
|
+
keyObjects.map(async (keyObject) => {
|
|
704
|
+
const keyId = keyObject.objectId;
|
|
705
|
+
if (keyObject.content && 'fields' in keyObject.content) {
|
|
706
|
+
const fields = keyObject.content.fields as any;
|
|
707
|
+
const obligationId = String(fields.ownership.fields.of);
|
|
708
|
+
const locked = await getObligationLocked(query, obligationId);
|
|
709
|
+
obligations.push({ id: obligationId, keyId, locked });
|
|
710
|
+
}
|
|
711
|
+
})
|
|
712
|
+
);
|
|
713
|
+
|
|
710
714
|
return obligations;
|
|
711
715
|
};
|
|
712
716
|
|
|
@@ -836,7 +840,7 @@ export const getMarketCoinAmounts = async (
|
|
|
836
840
|
const owner = ownerAddress || query.suiKit.currentAddress();
|
|
837
841
|
const marketCoins = {} as OptionalKeys<Record<SupportMarketCoins, number>>;
|
|
838
842
|
|
|
839
|
-
Promise.allSettled(
|
|
843
|
+
await Promise.allSettled(
|
|
840
844
|
marketCoinNames.map(async (marketCoinName) => {
|
|
841
845
|
const marketCoin = await getMarketCoinAmount(
|
|
842
846
|
query,
|
|
@@ -49,36 +49,44 @@ export const getLendings = async (
|
|
|
49
49
|
(SUPPORT_SPOOLS as readonly SupportMarketCoins[]).includes(marketCoinName)
|
|
50
50
|
) as SupportStakeMarketCoins[];
|
|
51
51
|
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
52
|
+
const [
|
|
53
|
+
marketPools,
|
|
54
|
+
spools,
|
|
55
|
+
coinAmounts,
|
|
56
|
+
marketCoinAmounts,
|
|
57
|
+
allStakeAccounts,
|
|
58
|
+
coinPrices,
|
|
59
|
+
] = await Promise.all([
|
|
60
|
+
query.getMarketPools(poolCoinNames, indexer),
|
|
61
|
+
query.getSpools(stakeMarketCoinNames, indexer),
|
|
62
|
+
query.getCoinAmounts(poolCoinNames, ownerAddress),
|
|
63
|
+
query.getMarketCoinAmounts(marketCoinNames, ownerAddress),
|
|
64
|
+
query.getAllStakeAccounts(ownerAddress),
|
|
65
|
+
query.utils.getCoinPrices(poolCoinNames),
|
|
66
|
+
]);
|
|
61
67
|
|
|
62
68
|
const lendings: Lendings = {};
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
(
|
|
66
|
-
marketCoinName
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
69
|
+
await Promise.allSettled(
|
|
70
|
+
poolCoinNames.map(async (poolCoinName) => {
|
|
71
|
+
const stakeMarketCoinName = stakeMarketCoinNames.find(
|
|
72
|
+
(marketCoinName) =>
|
|
73
|
+
marketCoinName === query.utils.parseMarketCoinName(poolCoinName)
|
|
74
|
+
);
|
|
75
|
+
const marketCoinName = query.utils.parseMarketCoinName(poolCoinName);
|
|
76
|
+
lendings[poolCoinName] = await getLending(
|
|
77
|
+
query,
|
|
78
|
+
poolCoinName,
|
|
79
|
+
ownerAddress,
|
|
80
|
+
indexer,
|
|
81
|
+
marketPools?.[poolCoinName],
|
|
82
|
+
stakeMarketCoinName ? spools[stakeMarketCoinName] : undefined,
|
|
83
|
+
stakeMarketCoinName ? allStakeAccounts[stakeMarketCoinName] : undefined,
|
|
84
|
+
coinAmounts?.[poolCoinName],
|
|
85
|
+
marketCoinAmounts?.[marketCoinName],
|
|
86
|
+
coinPrices?.[poolCoinName] ?? 0
|
|
87
|
+
);
|
|
88
|
+
})
|
|
89
|
+
);
|
|
82
90
|
|
|
83
91
|
return lendings;
|
|
84
92
|
};
|
|
@@ -28,15 +28,13 @@ export const getVescaKeys = async (
|
|
|
28
28
|
let hasNextPage = false;
|
|
29
29
|
let nextCursor: string | null | undefined = null;
|
|
30
30
|
do {
|
|
31
|
-
const paginatedKeyObjectsResponse = await query.
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
cursor: nextCursor,
|
|
39
|
-
});
|
|
31
|
+
const paginatedKeyObjectsResponse = await query.cache.queryGetOwnedObjects({
|
|
32
|
+
owner,
|
|
33
|
+
filter: {
|
|
34
|
+
StructType: veScaKeyType,
|
|
35
|
+
},
|
|
36
|
+
cursor: nextCursor,
|
|
37
|
+
});
|
|
40
38
|
keyObjectsResponse.push(...paginatedKeyObjectsResponse.data);
|
|
41
39
|
if (
|
|
42
40
|
paginatedKeyObjectsResponse.hasNextPage &&
|
package/src/utils/query.ts
CHANGED
|
@@ -173,19 +173,20 @@ export const calculateMarketPoolData = (
|
|
|
173
173
|
export const parseOriginMarketCollateralData = (
|
|
174
174
|
originMarketCollateralData: OriginMarketCollateralData
|
|
175
175
|
): ParsedMarketCollateralData => {
|
|
176
|
+
const divisor = 2 ** 32;
|
|
176
177
|
return {
|
|
177
178
|
coinType: normalizeStructTag(originMarketCollateralData.type.name),
|
|
178
179
|
collateralFactor:
|
|
179
|
-
Number(originMarketCollateralData.collateralFactor.value) /
|
|
180
|
+
Number(originMarketCollateralData.collateralFactor.value) / divisor,
|
|
180
181
|
liquidationFactor:
|
|
181
|
-
Number(originMarketCollateralData.liquidationFactor.value) /
|
|
182
|
+
Number(originMarketCollateralData.liquidationFactor.value) / divisor,
|
|
182
183
|
liquidationDiscount:
|
|
183
|
-
Number(originMarketCollateralData.liquidationDiscount.value) /
|
|
184
|
+
Number(originMarketCollateralData.liquidationDiscount.value) / divisor,
|
|
184
185
|
liquidationPanelty:
|
|
185
|
-
Number(originMarketCollateralData.liquidationPanelty.value) /
|
|
186
|
+
Number(originMarketCollateralData.liquidationPanelty.value) / divisor,
|
|
186
187
|
liquidationReserveFactor:
|
|
187
188
|
Number(originMarketCollateralData.liquidationReserveFactor.value) /
|
|
188
|
-
|
|
189
|
+
divisor,
|
|
189
190
|
maxCollateralAmount: Number(originMarketCollateralData.maxCollateralAmount),
|
|
190
191
|
totalCollateralAmount: Number(
|
|
191
192
|
originMarketCollateralData.totalCollateralAmount
|