@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
|
@@ -48,6 +48,7 @@ export type ObligationAccount = {
|
|
|
48
48
|
totalBorrowedPools: number;
|
|
49
49
|
collaterals: OptionalKeys<Record<SupportCollateralCoins, ObligationCollateral>>;
|
|
50
50
|
debts: OptionalKeys<Record<SupportPoolCoins, ObligationDebt>>;
|
|
51
|
+
borrowIncentives: OptionalKeys<Record<SupportPoolCoins, ObligationBorrowIncentive>>;
|
|
51
52
|
};
|
|
52
53
|
export type ObligationCollateral = {
|
|
53
54
|
coinName: SupportCollateralCoins;
|
|
@@ -81,6 +82,18 @@ export type ObligationDebt = {
|
|
|
81
82
|
availableRepayAmount: number;
|
|
82
83
|
availableRepayCoin: number;
|
|
83
84
|
};
|
|
85
|
+
export type ObligationBorrowIncentive = {
|
|
86
|
+
coinName: SupportPoolCoins;
|
|
87
|
+
coinType: string;
|
|
88
|
+
rewardCoinType: string;
|
|
89
|
+
symbol: string;
|
|
90
|
+
coinDecimal: number;
|
|
91
|
+
rewardCoinDecimal: number;
|
|
92
|
+
coinPrice: number;
|
|
93
|
+
rewardCoinPrice: number;
|
|
94
|
+
availableClaimAmount: number;
|
|
95
|
+
availableClaimCoin: number;
|
|
96
|
+
};
|
|
84
97
|
export type TotalValueLocked = {
|
|
85
98
|
supplyValue: number;
|
|
86
99
|
borrowValue: number;
|
package/package.json
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { normalizeStructTag } from '@mysten/sui.js/utils';
|
|
1
2
|
import { SuiTxBlock as SuiKitTxBlock } from '@scallop-io/sui-kit';
|
|
2
3
|
import { SUPPORT_BORROW_INCENTIVE_POOLS } from '../constants';
|
|
3
4
|
import {
|
|
@@ -49,7 +50,7 @@ export const queryBorrowIncentivePools = async (
|
|
|
49
50
|
|
|
50
51
|
const borrowIncentivePools: BorrowIncentivePools = {};
|
|
51
52
|
for (const pool of borrowIncentivePoolsQueryData.incentive_pools) {
|
|
52
|
-
const coinType =
|
|
53
|
+
const coinType = normalizeStructTag(pool.pool_type.name);
|
|
53
54
|
const coinName =
|
|
54
55
|
query.utils.parseCoinNameFromType<SupportBorrowIncentiveCoins>(coinType);
|
|
55
56
|
const rewardCoinName =
|
package/src/queries/coreQuery.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { normalizeStructTag } from '@mysten/sui.js/utils';
|
|
1
2
|
import { SuiTxBlock as SuiKitTxBlock } from '@scallop-io/sui-kit';
|
|
2
3
|
import BigNumber from 'bignumber.js';
|
|
3
4
|
import {
|
|
@@ -59,7 +60,7 @@ export const queryMarket = async (query: ScallopQuery) => {
|
|
|
59
60
|
const collaterals: MarketCollaterals = {};
|
|
60
61
|
|
|
61
62
|
for (const pool of marketData.pools) {
|
|
62
|
-
const coinType =
|
|
63
|
+
const coinType = normalizeStructTag(pool.type.name);
|
|
63
64
|
const poolCoinName =
|
|
64
65
|
query.utils.parseCoinNameFromType<SupportPoolCoins>(coinType);
|
|
65
66
|
const coinPrice =
|
|
@@ -115,7 +116,7 @@ export const queryMarket = async (query: ScallopQuery) => {
|
|
|
115
116
|
}
|
|
116
117
|
|
|
117
118
|
for (const collateral of marketData.collaterals) {
|
|
118
|
-
const coinType =
|
|
119
|
+
const coinType = normalizeStructTag(collateral.type.name);
|
|
119
120
|
const collateralCoinName =
|
|
120
121
|
query.utils.parseCoinNameFromType<SupportCollateralCoins>(coinType);
|
|
121
122
|
const coinPrice =
|
|
@@ -19,6 +19,7 @@ import type {
|
|
|
19
19
|
CoinPrices,
|
|
20
20
|
SupportMarketCoins,
|
|
21
21
|
TotalValueLocked,
|
|
22
|
+
SupportBorrowIncentiveCoins,
|
|
22
23
|
} from '../types';
|
|
23
24
|
|
|
24
25
|
/**
|
|
@@ -164,7 +165,9 @@ export const getLending = async (
|
|
|
164
165
|
availableUnstakeAmount = availableUnstakeAmount.plus(
|
|
165
166
|
accountStakedMarketCoinAmount
|
|
166
167
|
);
|
|
167
|
-
availableUnstakeCoin = availableUnstakeAmount.shiftedBy(
|
|
168
|
+
availableUnstakeCoin = availableUnstakeAmount.shiftedBy(
|
|
169
|
+
-1 * spool.coinDecimal
|
|
170
|
+
);
|
|
168
171
|
|
|
169
172
|
const baseIndexRate = 1_000_000_000;
|
|
170
173
|
const increasedPointRate = spool?.currentPointIndex
|
|
@@ -173,13 +176,15 @@ export const getLending = async (
|
|
|
173
176
|
)
|
|
174
177
|
: 1;
|
|
175
178
|
availableClaimAmount = availableClaimAmount.plus(
|
|
176
|
-
|
|
179
|
+
accountStakedMarketCoinAmount
|
|
177
180
|
.multipliedBy(increasedPointRate)
|
|
178
181
|
.plus(stakeAccount.points)
|
|
179
182
|
.multipliedBy(spool.exchangeRateNumerator)
|
|
180
183
|
.dividedBy(spool.exchangeRateDenominator)
|
|
181
184
|
);
|
|
182
|
-
availableClaimCoin = availableClaimAmount.shiftedBy(
|
|
185
|
+
availableClaimCoin = availableClaimAmount.shiftedBy(
|
|
186
|
+
-1 * spool.rewardCoinDecimal
|
|
187
|
+
);
|
|
183
188
|
}
|
|
184
189
|
}
|
|
185
190
|
|
|
@@ -298,12 +303,16 @@ export const getObligationAccount = async (
|
|
|
298
303
|
]),
|
|
299
304
|
];
|
|
300
305
|
const obligationQuery = await query.queryObligation(obligationId);
|
|
306
|
+
const borrowIncentivePools = await query.getBorrowIncentivePools();
|
|
307
|
+
const borrowIncentiveAccounts =
|
|
308
|
+
await query.getBorrowIncentiveAccounts(obligationId);
|
|
301
309
|
coinPrices = coinPrices || (await query.utils.getCoinPrices(assetCoinNames));
|
|
302
310
|
coinAmounts =
|
|
303
311
|
coinAmounts || (await query.getCoinAmounts(assetCoinNames, ownerAddress));
|
|
304
312
|
|
|
305
313
|
const collaterals: ObligationAccount['collaterals'] = {};
|
|
306
314
|
const debts: ObligationAccount['debts'] = {};
|
|
315
|
+
const borrowIncentives: ObligationAccount['borrowIncentives'] = {};
|
|
307
316
|
let totalDepositedPools = 0;
|
|
308
317
|
let totalDepositedValue = BigNumber(0);
|
|
309
318
|
let totalBorrowCapacityValue = BigNumber(0);
|
|
@@ -419,6 +428,50 @@ export const getObligationAccount = async (
|
|
|
419
428
|
}
|
|
420
429
|
}
|
|
421
430
|
|
|
431
|
+
for (const [poolCoinName, borrowIncentiveAccount] of Object.entries(
|
|
432
|
+
borrowIncentiveAccounts
|
|
433
|
+
)) {
|
|
434
|
+
const coinName = poolCoinName as SupportBorrowIncentiveCoins;
|
|
435
|
+
const borrowIncentivePool = borrowIncentivePools[coinName];
|
|
436
|
+
|
|
437
|
+
let availableClaimAmount = BigNumber(0);
|
|
438
|
+
let availableClaimCoin = BigNumber(0);
|
|
439
|
+
if (borrowIncentivePool) {
|
|
440
|
+
const accountBorrowedAmount = BigNumber(borrowIncentiveAccount.amount);
|
|
441
|
+
const baseIndexRate = 1_000_000_000;
|
|
442
|
+
const increasedPointRate = borrowIncentivePool.currentPointIndex
|
|
443
|
+
? BigNumber(
|
|
444
|
+
borrowIncentivePool.currentPointIndex - borrowIncentiveAccount.index
|
|
445
|
+
).dividedBy(baseIndexRate)
|
|
446
|
+
: 1;
|
|
447
|
+
availableClaimAmount = availableClaimAmount.plus(
|
|
448
|
+
accountBorrowedAmount
|
|
449
|
+
.multipliedBy(increasedPointRate)
|
|
450
|
+
.plus(borrowIncentiveAccount.points)
|
|
451
|
+
.multipliedBy(borrowIncentivePool.exchangeRateNumerator)
|
|
452
|
+
.dividedBy(borrowIncentivePool.exchangeRateDenominator)
|
|
453
|
+
);
|
|
454
|
+
availableClaimCoin = availableClaimAmount.shiftedBy(
|
|
455
|
+
-1 * borrowIncentivePool.rewardCoinDecimal
|
|
456
|
+
);
|
|
457
|
+
|
|
458
|
+
if (availableClaimAmount.isGreaterThan(0)) {
|
|
459
|
+
borrowIncentives[coinName] = {
|
|
460
|
+
coinName: borrowIncentivePool.coinName,
|
|
461
|
+
coinType: borrowIncentivePool.coinType,
|
|
462
|
+
rewardCoinType: borrowIncentivePool.rewardCoinType,
|
|
463
|
+
symbol: borrowIncentivePool.symbol,
|
|
464
|
+
coinDecimal: borrowIncentivePool.coinDecimal,
|
|
465
|
+
rewardCoinDecimal: borrowIncentivePool.rewardCoinDecimal,
|
|
466
|
+
coinPrice: borrowIncentivePool.coinPrice,
|
|
467
|
+
rewardCoinPrice: borrowIncentivePool.rewardCoinPrice,
|
|
468
|
+
availableClaimAmount: availableClaimAmount.toNumber(),
|
|
469
|
+
availableClaimCoin: availableClaimCoin.toNumber(),
|
|
470
|
+
};
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
|
|
422
475
|
let riskLevel =
|
|
423
476
|
totalRequiredCollateralValue.isZero() &&
|
|
424
477
|
totalBorrowedValueWithWeight.isZero()
|
|
@@ -472,6 +525,7 @@ export const getObligationAccount = async (
|
|
|
472
525
|
totalBorrowedPools,
|
|
473
526
|
collaterals,
|
|
474
527
|
debts,
|
|
528
|
+
borrowIncentives,
|
|
475
529
|
};
|
|
476
530
|
|
|
477
531
|
for (const [collateralCoinName, obligationCollateral] of Object.entries(
|
|
@@ -500,10 +554,10 @@ export const getObligationAccount = async (
|
|
|
500
554
|
.toNumber();
|
|
501
555
|
}
|
|
502
556
|
}
|
|
503
|
-
for (const [
|
|
557
|
+
for (const [poolCoinName, obligationDebt] of Object.entries(
|
|
504
558
|
obligationAccount.debts
|
|
505
559
|
)) {
|
|
506
|
-
const marketPool = market.pools[
|
|
560
|
+
const marketPool = market.pools[poolCoinName as SupportPoolCoins];
|
|
507
561
|
if (marketPool) {
|
|
508
562
|
const availableRepayAmount = BigNumber(
|
|
509
563
|
obligationDebt.availableRepayAmount
|
|
@@ -247,9 +247,9 @@ export const getStakeAccounts = async (
|
|
|
247
247
|
if (normalizeStructTag(type) === stakeMarketCoinTypes.ssui) {
|
|
248
248
|
stakeAccounts.ssui.push({
|
|
249
249
|
id,
|
|
250
|
-
type,
|
|
250
|
+
type: normalizeStructTag(type),
|
|
251
251
|
stakePoolId,
|
|
252
|
-
stakeType,
|
|
252
|
+
stakeType: normalizeStructTag(stakeType),
|
|
253
253
|
staked,
|
|
254
254
|
index,
|
|
255
255
|
points,
|
|
@@ -258,9 +258,9 @@ export const getStakeAccounts = async (
|
|
|
258
258
|
} else if (normalizeStructTag(type) === stakeMarketCoinTypes.susdc) {
|
|
259
259
|
stakeAccounts.susdc.push({
|
|
260
260
|
id,
|
|
261
|
-
type,
|
|
261
|
+
type: normalizeStructTag(type),
|
|
262
262
|
stakePoolId,
|
|
263
|
-
stakeType,
|
|
263
|
+
stakeType: normalizeStructTag(stakeType),
|
|
264
264
|
staked,
|
|
265
265
|
index,
|
|
266
266
|
points,
|
|
@@ -269,9 +269,9 @@ export const getStakeAccounts = async (
|
|
|
269
269
|
} else if (normalizeStructTag(type) === stakeMarketCoinTypes.susdt) {
|
|
270
270
|
stakeAccounts.susdt.push({
|
|
271
271
|
id,
|
|
272
|
-
type,
|
|
272
|
+
type: normalizeStructTag(type),
|
|
273
273
|
stakePoolId,
|
|
274
|
-
stakeType,
|
|
274
|
+
stakeType: normalizeStructTag(stakeType),
|
|
275
275
|
staked,
|
|
276
276
|
index,
|
|
277
277
|
points,
|
|
@@ -325,13 +325,13 @@ export const getStakePool = async (
|
|
|
325
325
|
const lastUpdate = Number(fields.last_update);
|
|
326
326
|
stakePool = {
|
|
327
327
|
id,
|
|
328
|
-
type,
|
|
328
|
+
type: normalizeStructTag(type),
|
|
329
329
|
maxPoint,
|
|
330
330
|
distributedPoint,
|
|
331
331
|
pointPerPeriod,
|
|
332
332
|
period,
|
|
333
333
|
maxStake,
|
|
334
|
-
stakeType,
|
|
334
|
+
stakeType: normalizeStructTag(stakeType),
|
|
335
335
|
totalStaked,
|
|
336
336
|
index,
|
|
337
337
|
createdAt,
|
|
@@ -384,7 +384,7 @@ export const getStakeRewardPool = async (
|
|
|
384
384
|
const claimedRewards = Number(fields.claimed_rewards);
|
|
385
385
|
stakeRewardPool = {
|
|
386
386
|
id,
|
|
387
|
-
type,
|
|
387
|
+
type: normalizeStructTag(type),
|
|
388
388
|
stakePoolId,
|
|
389
389
|
ratioNumerator,
|
|
390
390
|
ratioDenominator,
|
|
@@ -66,6 +66,9 @@ export type ObligationAccount = {
|
|
|
66
66
|
Record<SupportCollateralCoins, ObligationCollateral>
|
|
67
67
|
>;
|
|
68
68
|
debts: OptionalKeys<Record<SupportPoolCoins, ObligationDebt>>;
|
|
69
|
+
borrowIncentives: OptionalKeys<
|
|
70
|
+
Record<SupportPoolCoins, ObligationBorrowIncentive>
|
|
71
|
+
>;
|
|
69
72
|
};
|
|
70
73
|
|
|
71
74
|
export type ObligationCollateral = {
|
|
@@ -102,6 +105,19 @@ export type ObligationDebt = {
|
|
|
102
105
|
availableRepayCoin: number;
|
|
103
106
|
};
|
|
104
107
|
|
|
108
|
+
export type ObligationBorrowIncentive = {
|
|
109
|
+
coinName: SupportPoolCoins;
|
|
110
|
+
coinType: string;
|
|
111
|
+
rewardCoinType: string;
|
|
112
|
+
symbol: string;
|
|
113
|
+
coinDecimal: number;
|
|
114
|
+
rewardCoinDecimal: number;
|
|
115
|
+
coinPrice: number;
|
|
116
|
+
rewardCoinPrice: number;
|
|
117
|
+
availableClaimAmount: number;
|
|
118
|
+
availableClaimCoin: number;
|
|
119
|
+
};
|
|
120
|
+
|
|
105
121
|
export type TotalValueLocked = {
|
|
106
122
|
supplyValue: number;
|
|
107
123
|
borrowValue: number;
|
package/src/utils/query.ts
CHANGED
|
@@ -36,7 +36,7 @@ export const parseOriginMarketPoolData = (
|
|
|
36
36
|
originMarketPoolData: OriginMarketPoolData
|
|
37
37
|
): ParsedMarketPoolData => {
|
|
38
38
|
return {
|
|
39
|
-
coinType:
|
|
39
|
+
coinType: normalizeStructTag(originMarketPoolData.type.name),
|
|
40
40
|
// Parse origin data required for basic calculations.
|
|
41
41
|
maxBorrowRate: Number(originMarketPoolData.maxBorrowRate.value) / 2 ** 32,
|
|
42
42
|
borrowRate: Number(originMarketPoolData.interestRate.value) / 2 ** 32,
|
|
@@ -171,7 +171,7 @@ export const parseOriginMarketCollateralData = (
|
|
|
171
171
|
originMarketCollateralData: OriginMarketCollateralData
|
|
172
172
|
): ParsedMarketCollateralData => {
|
|
173
173
|
return {
|
|
174
|
-
coinType:
|
|
174
|
+
coinType: normalizeStructTag(originMarketCollateralData.type.name),
|
|
175
175
|
collateralFactor:
|
|
176
176
|
Number(originMarketCollateralData.collateralFactor.value) / 2 ** 32,
|
|
177
177
|
liquidationFactor:
|
|
@@ -225,7 +225,7 @@ export const parseOriginSpoolData = (
|
|
|
225
225
|
originSpoolData: OriginSpoolData
|
|
226
226
|
): ParsedSpoolData => {
|
|
227
227
|
return {
|
|
228
|
-
stakeType:
|
|
228
|
+
stakeType: normalizeStructTag(originSpoolData.stakeType.fields.name),
|
|
229
229
|
maxPoint: Number(originSpoolData.maxDistributedPoint),
|
|
230
230
|
distributedPoint: Number(originSpoolData.distributedPoint),
|
|
231
231
|
pointPerPeriod: Number(originSpoolData.distributedPointPerPeriod),
|