@scallop-io/sui-scallop-sdk 0.44.2 → 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/builders/borrowIncentiveBuilder.d.ts +12 -0
- package/dist/constants/common.d.ts +3 -1
- package/dist/constants/enum.d.ts +3 -2
- package/dist/index.js +815 -228
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +776 -192
- package/dist/index.mjs.map +1 -1
- package/dist/models/scallopClient.d.ts +33 -2
- package/dist/models/scallopQuery.d.ts +31 -10
- package/dist/models/scallopUtils.d.ts +11 -4
- package/dist/queries/borrowIncentiveQuery.d.ts +24 -0
- package/dist/queries/coreQuery.d.ts +8 -0
- package/dist/queries/index.d.ts +1 -0
- package/dist/queries/spoolQuery.d.ts +13 -5
- package/dist/types/address.d.ts +8 -0
- package/dist/types/builder/borrowIncentive.d.ts +31 -0
- package/dist/types/builder/index.d.ts +3 -1
- package/dist/types/constant/common.d.ts +5 -3
- package/dist/types/constant/enum.d.ts +6 -3
- package/dist/types/query/borrowIncentive.d.ts +118 -0
- package/dist/types/query/core.d.ts +1 -0
- package/dist/types/query/index.d.ts +1 -0
- package/dist/types/query/portfolio.d.ts +13 -0
- package/dist/types/query/spool.d.ts +12 -13
- package/dist/utils/builder.d.ts +8 -0
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/query.d.ts +33 -10
- package/dist/utils/util.d.ts +13 -0
- package/package.json +1 -1
- package/src/builders/borrowIncentiveBuilder.ts +257 -0
- package/src/builders/coreBuilder.ts +1 -14
- package/src/builders/index.ts +9 -2
- package/src/builders/spoolBuilder.ts +3 -16
- package/src/constants/common.ts +4 -1
- package/src/constants/enum.ts +8 -2
- package/src/models/scallopAddress.ts +8 -0
- package/src/models/scallopClient.ts +104 -2
- package/src/models/scallopQuery.ts +48 -14
- package/src/models/scallopUtils.ts +21 -5
- package/src/queries/borrowIncentiveQuery.ts +167 -0
- package/src/queries/coreQuery.ts +58 -15
- package/src/queries/index.ts +1 -0
- package/src/queries/portfolioQuery.ts +59 -5
- package/src/queries/spoolQuery.ts +87 -71
- package/src/types/address.ts +8 -0
- package/src/types/builder/borrowIncentive.ts +67 -0
- package/src/types/builder/index.ts +5 -1
- package/src/types/builder/spool.ts +0 -1
- package/src/types/constant/common.ts +10 -3
- package/src/types/constant/enum.ts +9 -3
- package/src/types/query/borrowIncentive.ts +150 -0
- package/src/types/query/core.ts +1 -1
- package/src/types/query/index.ts +1 -0
- package/src/types/query/portfolio.ts +16 -0
- package/src/types/query/spool.ts +28 -18
- package/src/utils/builder.ts +15 -0
- package/src/utils/index.ts +1 -1
- package/src/utils/query.ts +279 -72
- package/src/utils/util.ts +36 -2
- package/dist/utils/oracle.d.ts +0 -14
- package/src/utils/oracle.ts +0 -36
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
queryObligation,
|
|
7
7
|
getStakeAccounts,
|
|
8
8
|
getStakePool,
|
|
9
|
-
|
|
9
|
+
getStakeRewardPool,
|
|
10
10
|
getPythPrice,
|
|
11
11
|
getMarketPools,
|
|
12
12
|
getMarketPool,
|
|
@@ -14,6 +14,8 @@ import {
|
|
|
14
14
|
getMarketCollateral,
|
|
15
15
|
getSpools,
|
|
16
16
|
getSpool,
|
|
17
|
+
queryBorrowIncentivePools,
|
|
18
|
+
queryBorrowIncentiveAccounts,
|
|
17
19
|
getCoinAmounts,
|
|
18
20
|
getCoinAmount,
|
|
19
21
|
getMarketCoinAmounts,
|
|
@@ -33,7 +35,8 @@ import {
|
|
|
33
35
|
SupportCollateralCoins,
|
|
34
36
|
SupportMarketCoins,
|
|
35
37
|
StakePools,
|
|
36
|
-
|
|
38
|
+
StakeRewardPools,
|
|
39
|
+
SupportBorrowIncentiveCoins,
|
|
37
40
|
} from '../types';
|
|
38
41
|
import { ScallopAddress } from './scallopAddress';
|
|
39
42
|
import { ScallopUtils } from './scallopUtils';
|
|
@@ -323,43 +326,74 @@ export class ScallopQuery {
|
|
|
323
326
|
}
|
|
324
327
|
|
|
325
328
|
/**
|
|
326
|
-
* Get reward pools data.
|
|
329
|
+
* Get stake reward pools data.
|
|
327
330
|
*
|
|
328
331
|
* @description
|
|
329
332
|
* For backward compatible, it is recommended to use `getSpools` method
|
|
330
333
|
* to get all spools data.
|
|
331
334
|
*
|
|
332
335
|
* @param stakeMarketCoinNames - Specific an array of stake market coin name.
|
|
333
|
-
* @return
|
|
336
|
+
* @return Stake reward pools data.
|
|
334
337
|
*/
|
|
335
|
-
public async
|
|
338
|
+
public async getStakeRewardPools(
|
|
336
339
|
stakeMarketCoinNames?: SupportStakeMarketCoins[]
|
|
337
340
|
) {
|
|
338
341
|
stakeMarketCoinNames = stakeMarketCoinNames ?? [...SUPPORT_SPOOLS];
|
|
339
|
-
const
|
|
342
|
+
const stakeRewardPools: StakeRewardPools = {};
|
|
340
343
|
for (const stakeMarketCoinName of stakeMarketCoinNames) {
|
|
341
|
-
const
|
|
344
|
+
const stakeRewardPool = await getStakeRewardPool(
|
|
345
|
+
this,
|
|
346
|
+
stakeMarketCoinName
|
|
347
|
+
);
|
|
342
348
|
|
|
343
|
-
if (
|
|
344
|
-
|
|
349
|
+
if (stakeRewardPool) {
|
|
350
|
+
stakeRewardPools[stakeMarketCoinName] = stakeRewardPool;
|
|
345
351
|
}
|
|
346
352
|
}
|
|
347
353
|
|
|
348
|
-
return
|
|
354
|
+
return stakeRewardPools;
|
|
349
355
|
}
|
|
350
356
|
|
|
351
357
|
/**
|
|
352
|
-
* Get reward pool data.
|
|
358
|
+
* Get stake reward pool data.
|
|
353
359
|
*
|
|
354
360
|
* @description
|
|
355
361
|
* For backward compatible, it is recommended to use `getSpool` method
|
|
356
362
|
* to get spool data.
|
|
357
363
|
*
|
|
358
364
|
* @param marketCoinName - Specific support stake market coin name.
|
|
359
|
-
* @return
|
|
365
|
+
* @return Stake reward pool data.
|
|
360
366
|
*/
|
|
361
|
-
public async
|
|
362
|
-
|
|
367
|
+
public async getStakeRewardPool(
|
|
368
|
+
stakeMarketCoinName: SupportStakeMarketCoins
|
|
369
|
+
) {
|
|
370
|
+
return await getStakeRewardPool(this, stakeMarketCoinName);
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
/**
|
|
374
|
+
* Get borrow incentive pools data.
|
|
375
|
+
*
|
|
376
|
+
* @param coinNames - Specific an array of support borrow incentive coin name.
|
|
377
|
+
* @return Borrow incentive pools data.
|
|
378
|
+
*/
|
|
379
|
+
public async getBorrowIncentivePools(
|
|
380
|
+
coinNames?: SupportBorrowIncentiveCoins[]
|
|
381
|
+
) {
|
|
382
|
+
return await queryBorrowIncentivePools(this, coinNames);
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
/**
|
|
386
|
+
* Get borrow incentive accounts data.
|
|
387
|
+
*
|
|
388
|
+
* @param coinNames - Specific support borrow incentive coin name.
|
|
389
|
+
* @param ownerAddress - The owner address.
|
|
390
|
+
* @return Borrow incentive accounts data.
|
|
391
|
+
*/
|
|
392
|
+
public async getBorrowIncentiveAccounts(
|
|
393
|
+
obligationId: string,
|
|
394
|
+
coinNames?: SupportBorrowIncentiveCoins[]
|
|
395
|
+
) {
|
|
396
|
+
return await queryBorrowIncentiveAccounts(this, obligationId, coinNames);
|
|
363
397
|
}
|
|
364
398
|
|
|
365
399
|
/**
|
|
@@ -8,7 +8,8 @@ import {
|
|
|
8
8
|
PROTOCOL_OBJECT_ID,
|
|
9
9
|
SUPPORT_POOLS,
|
|
10
10
|
SUPPORT_COLLATERALS,
|
|
11
|
-
|
|
11
|
+
spoolRewardCoins,
|
|
12
|
+
borrowIncentiveRewardCoins,
|
|
12
13
|
coinDecimals,
|
|
13
14
|
wormholeCoinIds,
|
|
14
15
|
voloCoinIds,
|
|
@@ -27,6 +28,7 @@ import type {
|
|
|
27
28
|
SupportAssetCoins,
|
|
28
29
|
SupportMarketCoins,
|
|
29
30
|
SupportStakeMarketCoins,
|
|
31
|
+
SupportBorrowIncentiveCoins,
|
|
30
32
|
CoinPrices,
|
|
31
33
|
PriceMap,
|
|
32
34
|
CoinWrappedType,
|
|
@@ -246,13 +248,27 @@ export class ScallopUtils {
|
|
|
246
248
|
}
|
|
247
249
|
|
|
248
250
|
/**
|
|
249
|
-
* Get reward type of
|
|
251
|
+
* Get reward type of spool.
|
|
250
252
|
*
|
|
251
253
|
* @param stakeMarketCoinName - Support stake market coin.
|
|
252
|
-
* @return
|
|
254
|
+
* @return Spool reward coin name.
|
|
253
255
|
*/
|
|
254
|
-
public
|
|
255
|
-
|
|
256
|
+
public getSpoolRewardCoinName = (
|
|
257
|
+
stakeMarketCoinName: SupportStakeMarketCoins
|
|
258
|
+
) => {
|
|
259
|
+
return spoolRewardCoins[stakeMarketCoinName];
|
|
260
|
+
};
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* Get reward type of borrow incentive pool.
|
|
264
|
+
*
|
|
265
|
+
* @param borrowIncentiveCoinName - Support borrow incentive coin.
|
|
266
|
+
* @return Borrow incentive reward coin name.
|
|
267
|
+
*/
|
|
268
|
+
public getBorrowIncentiveRewardCoinName = (
|
|
269
|
+
borrowIncentiveCoinName: SupportBorrowIncentiveCoins
|
|
270
|
+
) => {
|
|
271
|
+
return borrowIncentiveRewardCoins[borrowIncentiveCoinName];
|
|
256
272
|
};
|
|
257
273
|
|
|
258
274
|
/**
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import { normalizeStructTag } from '@mysten/sui.js/utils';
|
|
2
|
+
import { SuiTxBlock as SuiKitTxBlock } from '@scallop-io/sui-kit';
|
|
3
|
+
import { SUPPORT_BORROW_INCENTIVE_POOLS } from '../constants';
|
|
4
|
+
import {
|
|
5
|
+
parseOriginBorrowIncentivePoolData,
|
|
6
|
+
calculateBorrowIncentivePoolData,
|
|
7
|
+
parseOriginBorrowIncentiveRewardPoolData,
|
|
8
|
+
calculateBorrowIncentiveRewardPoolData,
|
|
9
|
+
parseOriginBorrowIncentiveAccountData,
|
|
10
|
+
} from '../utils';
|
|
11
|
+
import type { ScallopQuery } from '../models';
|
|
12
|
+
import type {
|
|
13
|
+
BorrowIncentivePoolsQueryInterface,
|
|
14
|
+
BorrowIncentivePools,
|
|
15
|
+
BorrowIncentiveAccountsQueryInterface,
|
|
16
|
+
BorrowIncentiveAccounts,
|
|
17
|
+
SupportBorrowIncentiveCoins,
|
|
18
|
+
SupportAssetCoins,
|
|
19
|
+
} from '../types';
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Query borrow incentive pools data.
|
|
23
|
+
*
|
|
24
|
+
* @param query - The Scallop query instance.
|
|
25
|
+
* @param borrowIncentiveCoinNames - Specific an array of support borrow incentive coin name.
|
|
26
|
+
* @return Borrow incentive pools data.
|
|
27
|
+
*/
|
|
28
|
+
export const queryBorrowIncentivePools = async (
|
|
29
|
+
query: ScallopQuery,
|
|
30
|
+
borrowIncentiveCoinNames?: SupportBorrowIncentiveCoins[]
|
|
31
|
+
) => {
|
|
32
|
+
borrowIncentiveCoinNames = borrowIncentiveCoinNames || [
|
|
33
|
+
...SUPPORT_BORROW_INCENTIVE_POOLS,
|
|
34
|
+
];
|
|
35
|
+
const queryPkgId = query.address.get('borrowIncentive.query');
|
|
36
|
+
const incentivePoolsId = query.address.get('borrowIncentive.incentivePools');
|
|
37
|
+
const txBlock = new SuiKitTxBlock();
|
|
38
|
+
const queryTarget = `${queryPkgId}::incentive_pools_query::incentive_pools_data`;
|
|
39
|
+
// The reward coin type currently only support sui, so bring it in directly here.
|
|
40
|
+
txBlock.moveCall(queryTarget, [incentivePoolsId], ['0x2::sui::SUI']);
|
|
41
|
+
const queryResult = await query.suiKit.inspectTxn(txBlock);
|
|
42
|
+
const borrowIncentivePoolsQueryData = queryResult.events[0]
|
|
43
|
+
.parsedJson as BorrowIncentivePoolsQueryInterface;
|
|
44
|
+
|
|
45
|
+
const parsedBorrowIncentiveRewardPoolData =
|
|
46
|
+
parseOriginBorrowIncentiveRewardPoolData(
|
|
47
|
+
borrowIncentivePoolsQueryData.reward_pool
|
|
48
|
+
);
|
|
49
|
+
const rewardCoinType = parsedBorrowIncentiveRewardPoolData.rewardType;
|
|
50
|
+
|
|
51
|
+
const borrowIncentivePools: BorrowIncentivePools = {};
|
|
52
|
+
for (const pool of borrowIncentivePoolsQueryData.incentive_pools) {
|
|
53
|
+
const coinType = normalizeStructTag(pool.pool_type.name);
|
|
54
|
+
const coinName =
|
|
55
|
+
query.utils.parseCoinNameFromType<SupportBorrowIncentiveCoins>(coinType);
|
|
56
|
+
const rewardCoinName =
|
|
57
|
+
query.utils.parseCoinNameFromType<SupportAssetCoins>(rewardCoinType);
|
|
58
|
+
|
|
59
|
+
// Filter pools not yet supported by the SDK.
|
|
60
|
+
if (!borrowIncentiveCoinNames.includes(coinName)) {
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const coinPrices = await query.utils.getCoinPrices([
|
|
65
|
+
coinName,
|
|
66
|
+
rewardCoinName,
|
|
67
|
+
]);
|
|
68
|
+
|
|
69
|
+
const parsedBorrowIncentivePoolData =
|
|
70
|
+
parseOriginBorrowIncentivePoolData(pool);
|
|
71
|
+
|
|
72
|
+
const coinPrice = coinPrices?.[coinName] ?? 0;
|
|
73
|
+
const coinDecimal = query.utils.getCoinDecimal(coinName);
|
|
74
|
+
const calculatedBorrowIncentivePoolData = calculateBorrowIncentivePoolData(
|
|
75
|
+
parsedBorrowIncentivePoolData,
|
|
76
|
+
coinPrice,
|
|
77
|
+
coinDecimal
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
const rewardCoinPrice = coinPrices?.[rewardCoinName] ?? 0;
|
|
81
|
+
const rewardCoinDecimal = query.utils.getCoinDecimal(rewardCoinName);
|
|
82
|
+
const calculatedBorrowIncentiveRewardPoolData =
|
|
83
|
+
calculateBorrowIncentiveRewardPoolData(
|
|
84
|
+
parsedBorrowIncentivePoolData,
|
|
85
|
+
parsedBorrowIncentiveRewardPoolData,
|
|
86
|
+
calculatedBorrowIncentivePoolData,
|
|
87
|
+
rewardCoinPrice,
|
|
88
|
+
rewardCoinDecimal
|
|
89
|
+
);
|
|
90
|
+
|
|
91
|
+
borrowIncentivePools[coinName] = {
|
|
92
|
+
coinName: coinName,
|
|
93
|
+
symbol: query.utils.parseSymbol(coinName),
|
|
94
|
+
coinType: coinType,
|
|
95
|
+
rewardCoinType: rewardCoinType,
|
|
96
|
+
coinDecimal: coinDecimal,
|
|
97
|
+
rewardCoinDecimal: rewardCoinDecimal,
|
|
98
|
+
coinPrice: coinPrice,
|
|
99
|
+
rewardCoinPrice: rewardCoinPrice,
|
|
100
|
+
maxPoint: parsedBorrowIncentivePoolData.maxPoint,
|
|
101
|
+
distributedPoint: parsedBorrowIncentivePoolData.distributedPoint,
|
|
102
|
+
maxStake: parsedBorrowIncentivePoolData.maxStake,
|
|
103
|
+
...calculatedBorrowIncentivePoolData,
|
|
104
|
+
exchangeRateNumerator:
|
|
105
|
+
parsedBorrowIncentiveRewardPoolData.exchangeRateNumerator,
|
|
106
|
+
exchangeRateDenominator:
|
|
107
|
+
parsedBorrowIncentiveRewardPoolData.exchangeRateDenominator,
|
|
108
|
+
...calculatedBorrowIncentiveRewardPoolData,
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return borrowIncentivePools;
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Query borrow incentive accounts data.
|
|
117
|
+
*
|
|
118
|
+
* @param query - The Scallop query instance.
|
|
119
|
+
* @param borrowIncentiveCoinNames - Specific an array of support borrow incentive coin name.
|
|
120
|
+
* @return Borrow incentive accounts data.
|
|
121
|
+
*/
|
|
122
|
+
export const queryBorrowIncentiveAccounts = async (
|
|
123
|
+
query: ScallopQuery,
|
|
124
|
+
obligationId: string,
|
|
125
|
+
borrowIncentiveCoinNames?: SupportBorrowIncentiveCoins[]
|
|
126
|
+
) => {
|
|
127
|
+
borrowIncentiveCoinNames = borrowIncentiveCoinNames || [
|
|
128
|
+
...SUPPORT_BORROW_INCENTIVE_POOLS,
|
|
129
|
+
];
|
|
130
|
+
const queryPkgId = query.address.get('borrowIncentive.query');
|
|
131
|
+
const incentiveAccountsId = query.address.get(
|
|
132
|
+
'borrowIncentive.incentiveAccounts'
|
|
133
|
+
);
|
|
134
|
+
const queryTarget = `${queryPkgId}::incentive_account_query::incentive_account_data`;
|
|
135
|
+
const txBlock = new SuiKitTxBlock();
|
|
136
|
+
txBlock.moveCall(queryTarget, [incentiveAccountsId, obligationId]);
|
|
137
|
+
const queryResult = await query.suiKit.inspectTxn(txBlock);
|
|
138
|
+
const borrowIncentiveAccountsQueryData = queryResult.events[0]
|
|
139
|
+
.parsedJson as BorrowIncentiveAccountsQueryInterface;
|
|
140
|
+
|
|
141
|
+
const borrowIncentiveAccounts: BorrowIncentiveAccounts = Object.values(
|
|
142
|
+
borrowIncentiveAccountsQueryData.incentive_states
|
|
143
|
+
).reduce((accounts, accountData) => {
|
|
144
|
+
const parsedBorrowIncentiveAccount =
|
|
145
|
+
parseOriginBorrowIncentiveAccountData(accountData);
|
|
146
|
+
const poolType = parsedBorrowIncentiveAccount.poolType;
|
|
147
|
+
const coinName =
|
|
148
|
+
query.utils.parseCoinNameFromType<SupportBorrowIncentiveCoins>(poolType);
|
|
149
|
+
|
|
150
|
+
if (
|
|
151
|
+
borrowIncentiveCoinNames &&
|
|
152
|
+
borrowIncentiveCoinNames.includes(coinName)
|
|
153
|
+
) {
|
|
154
|
+
accounts[coinName] = {
|
|
155
|
+
poolType: poolType,
|
|
156
|
+
amount: parsedBorrowIncentiveAccount.amount,
|
|
157
|
+
points: parsedBorrowIncentiveAccount.points,
|
|
158
|
+
totalPoints: parsedBorrowIncentiveAccount.totalPoints,
|
|
159
|
+
index: parsedBorrowIncentiveAccount.index,
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
return accounts;
|
|
164
|
+
}, {} as BorrowIncentiveAccounts);
|
|
165
|
+
|
|
166
|
+
return borrowIncentiveAccounts;
|
|
167
|
+
};
|
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,6 +60,17 @@ export const queryMarket = async (query: ScallopQuery) => {
|
|
|
59
60
|
const collaterals: MarketCollaterals = {};
|
|
60
61
|
|
|
61
62
|
for (const pool of marketData.pools) {
|
|
63
|
+
const coinType = normalizeStructTag(pool.type.name);
|
|
64
|
+
const poolCoinName =
|
|
65
|
+
query.utils.parseCoinNameFromType<SupportPoolCoins>(coinType);
|
|
66
|
+
const coinPrice =
|
|
67
|
+
(await query.utils.getCoinPrices([poolCoinName]))?.[poolCoinName] ?? 0;
|
|
68
|
+
|
|
69
|
+
// Filter pools not yet supported by the SDK.
|
|
70
|
+
if (!SUPPORT_POOLS.includes(poolCoinName)) {
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
|
|
62
74
|
const parsedMarketPoolData = parseOriginMarketPoolData({
|
|
63
75
|
type: pool.type,
|
|
64
76
|
maxBorrowRate: pool.maxBorrowRate,
|
|
@@ -85,12 +97,6 @@ export const queryMarket = async (query: ScallopQuery) => {
|
|
|
85
97
|
parsedMarketPoolData
|
|
86
98
|
);
|
|
87
99
|
|
|
88
|
-
const coinType = '0x' + pool.type.name;
|
|
89
|
-
const poolCoinName =
|
|
90
|
-
query.utils.parseCoinNameFromType<SupportPoolCoins>(coinType);
|
|
91
|
-
const coinPrice =
|
|
92
|
-
(await query.utils.getCoinPrices([poolCoinName]))?.[poolCoinName] ?? 0;
|
|
93
|
-
|
|
94
100
|
pools[poolCoinName] = {
|
|
95
101
|
coinName: poolCoinName,
|
|
96
102
|
symbol: query.utils.parseSymbol(poolCoinName),
|
|
@@ -110,6 +116,19 @@ export const queryMarket = async (query: ScallopQuery) => {
|
|
|
110
116
|
}
|
|
111
117
|
|
|
112
118
|
for (const collateral of marketData.collaterals) {
|
|
119
|
+
const coinType = normalizeStructTag(collateral.type.name);
|
|
120
|
+
const collateralCoinName =
|
|
121
|
+
query.utils.parseCoinNameFromType<SupportCollateralCoins>(coinType);
|
|
122
|
+
const coinPrice =
|
|
123
|
+
(await query.utils.getCoinPrices([collateralCoinName]))?.[
|
|
124
|
+
collateralCoinName
|
|
125
|
+
] ?? 0;
|
|
126
|
+
|
|
127
|
+
// Filter collaterals not yet supported by the SDK.
|
|
128
|
+
if (!SUPPORT_COLLATERALS.includes(collateralCoinName)) {
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
|
|
113
132
|
const parsedMarketCollateralData = parseOriginMarketCollateralData({
|
|
114
133
|
type: collateral.type,
|
|
115
134
|
collateralFactor: collateral.collateralFactor,
|
|
@@ -126,14 +145,6 @@ export const queryMarket = async (query: ScallopQuery) => {
|
|
|
126
145
|
parsedMarketCollateralData
|
|
127
146
|
);
|
|
128
147
|
|
|
129
|
-
const coinType = '0x' + collateral.type.name;
|
|
130
|
-
const collateralCoinName =
|
|
131
|
-
query.utils.parseCoinNameFromType<SupportCollateralCoins>(coinType);
|
|
132
|
-
const coinPrice =
|
|
133
|
-
(await query.utils.getCoinPrices([collateralCoinName]))?.[
|
|
134
|
-
collateralCoinName
|
|
135
|
-
] ?? 0;
|
|
136
|
-
|
|
137
148
|
collaterals[collateralCoinName] = {
|
|
138
149
|
coinName: collateralCoinName,
|
|
139
150
|
symbol: query.utils.parseSymbol(collateralCoinName),
|
|
@@ -586,12 +597,44 @@ export const getObligations = async (
|
|
|
586
597
|
if (keyObject.content && 'fields' in keyObject.content) {
|
|
587
598
|
const fields = keyObject.content.fields as any;
|
|
588
599
|
const obligationId = String(fields.ownership.fields.of);
|
|
589
|
-
|
|
600
|
+
const locked = await getObligationLocked(query, obligationId);
|
|
601
|
+
obligations.push({ id: obligationId, keyId, locked });
|
|
590
602
|
}
|
|
591
603
|
}
|
|
592
604
|
return obligations;
|
|
593
605
|
};
|
|
594
606
|
|
|
607
|
+
/**
|
|
608
|
+
* Query obligation locked status.
|
|
609
|
+
*
|
|
610
|
+
* @param query - The Scallop query instance.
|
|
611
|
+
* @param obligationId - The obligation id.
|
|
612
|
+
* @return Obligation locked status.
|
|
613
|
+
*/
|
|
614
|
+
export const getObligationLocked = async (
|
|
615
|
+
query: ScallopQuery,
|
|
616
|
+
obligationId: string
|
|
617
|
+
) => {
|
|
618
|
+
const obligationObjectResponse = await query.suiKit.client().getObject({
|
|
619
|
+
id: obligationId,
|
|
620
|
+
options: {
|
|
621
|
+
showContent: true,
|
|
622
|
+
},
|
|
623
|
+
});
|
|
624
|
+
let obligationLocked = false;
|
|
625
|
+
if (
|
|
626
|
+
obligationObjectResponse.data &&
|
|
627
|
+
obligationObjectResponse?.data?.content?.dataType === 'moveObject' &&
|
|
628
|
+
'lock_key' in obligationObjectResponse.data.content.fields
|
|
629
|
+
) {
|
|
630
|
+
obligationLocked = Boolean(
|
|
631
|
+
obligationObjectResponse.data.content.fields.lock_key
|
|
632
|
+
);
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
return obligationLocked;
|
|
636
|
+
};
|
|
637
|
+
|
|
595
638
|
/**
|
|
596
639
|
* Query obligation data.
|
|
597
640
|
*
|
package/src/queries/index.ts
CHANGED
|
@@ -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
|