@scallop-io/sui-scallop-sdk 1.4.0 → 1.4.1
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/constants/common.d.ts +1 -1
- package/dist/constants/enum.d.ts +1 -1
- package/dist/index.js +156 -107
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +155 -106
- package/dist/index.mjs.map +1 -1
- package/dist/models/scallopClient.d.ts +4 -4
- package/dist/models/scallopQuery.d.ts +42 -0
- package/dist/models/scallopUtils.d.ts +10 -10
- package/dist/queries/borrowIncentiveQuery.d.ts +2 -2
- package/dist/queries/priceQuery.d.ts +36 -2
- package/dist/types/builder/borrowIncentive.d.ts +6 -6
- package/dist/types/constant/common.d.ts +1 -1
- package/dist/types/utils.d.ts +2 -6
- package/package.json +1 -1
- package/src/builders/borrowIncentiveBuilder.ts +2 -13
- package/src/constants/common.ts +4 -2
- package/src/constants/enum.ts +11 -16
- package/src/models/scallopClient.ts +27 -10
- package/src/models/scallopQuery.ts +18 -1
- package/src/models/scallopUtils.ts +23 -18
- package/src/queries/borrowIncentiveQuery.ts +29 -12
- package/src/queries/coreQuery.ts +4 -10
- package/src/queries/portfolioQuery.ts +65 -62
- package/src/queries/priceQuery.ts +35 -2
- package/src/queries/sCoinQuery.ts +1 -1
- package/src/queries/spoolQuery.ts +2 -4
- package/src/types/builder/borrowIncentive.ts +10 -15
- package/src/types/constant/common.ts +1 -2
- package/src/types/utils.ts +2 -10
- package/src/utils/query.ts +0 -87
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { normalizeStructTag } from '@mysten/sui/utils';
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
sCoinRawNameToName,
|
|
4
|
+
SUPPORT_BORROW_INCENTIVE_POOLS,
|
|
5
|
+
SUPPORT_BORROW_INCENTIVE_REWARDS,
|
|
6
|
+
} from '../constants';
|
|
3
7
|
import {
|
|
4
8
|
parseOriginBorrowIncentivePoolData,
|
|
5
9
|
parseOriginBorrowIncentiveAccountData,
|
|
@@ -17,6 +21,7 @@ import type {
|
|
|
17
21
|
OptionalKeys,
|
|
18
22
|
BorrowIncentivePool,
|
|
19
23
|
CoinPrices,
|
|
24
|
+
MarketPools,
|
|
20
25
|
} from '../types';
|
|
21
26
|
import BigNumber from 'bignumber.js';
|
|
22
27
|
|
|
@@ -55,11 +60,14 @@ export const getBorrowIncentivePools = async (
|
|
|
55
60
|
...SUPPORT_BORROW_INCENTIVE_POOLS,
|
|
56
61
|
],
|
|
57
62
|
indexer: boolean = false,
|
|
63
|
+
marketPools?: MarketPools,
|
|
58
64
|
coinPrices?: CoinPrices
|
|
59
65
|
) => {
|
|
60
66
|
const borrowIncentivePools: BorrowIncentivePools = {};
|
|
61
|
-
|
|
62
|
-
|
|
67
|
+
marketPools =
|
|
68
|
+
marketPools ??
|
|
69
|
+
(await query.getMarketPools(undefined, { coinPrices, indexer }));
|
|
70
|
+
coinPrices = coinPrices ?? (await query.getAllCoinPrices({ marketPools }));
|
|
63
71
|
|
|
64
72
|
if (indexer) {
|
|
65
73
|
const borrowIncentivePoolsIndexer =
|
|
@@ -67,7 +75,13 @@ export const getBorrowIncentivePools = async (
|
|
|
67
75
|
|
|
68
76
|
const updateBorrowIncentivePool = (pool: BorrowIncentivePool) => {
|
|
69
77
|
if (!borrowIncentiveCoinNames.includes(pool.coinName)) return;
|
|
70
|
-
pool.coinPrice = coinPrices[pool.coinName]
|
|
78
|
+
pool.coinPrice = coinPrices[pool.coinName] || pool.coinPrice;
|
|
79
|
+
for (const sCoinName of SUPPORT_BORROW_INCENTIVE_REWARDS) {
|
|
80
|
+
if (pool.points[sCoinName]) {
|
|
81
|
+
pool.points[sCoinName].coinPrice =
|
|
82
|
+
coinPrices[sCoinName] ?? pool.points[sCoinName].coinPrice;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
71
85
|
borrowIncentivePools[pool.coinName] = pool;
|
|
72
86
|
};
|
|
73
87
|
|
|
@@ -94,7 +108,6 @@ export const getBorrowIncentivePools = async (
|
|
|
94
108
|
query.utils.parseCoinNameFromType<SupportBorrowIncentiveCoins>(
|
|
95
109
|
poolCoinType
|
|
96
110
|
);
|
|
97
|
-
|
|
98
111
|
const poolCoinPrice = coinPrices?.[poolCoinName] ?? 0;
|
|
99
112
|
const poolCoinDecimal = query.utils.getCoinDecimal(poolCoinName);
|
|
100
113
|
|
|
@@ -102,17 +115,21 @@ export const getBorrowIncentivePools = async (
|
|
|
102
115
|
if (!borrowIncentiveCoinNames.includes(poolCoinName)) {
|
|
103
116
|
continue;
|
|
104
117
|
}
|
|
105
|
-
|
|
118
|
+
|
|
119
|
+
// pool points for borrow incentive reward
|
|
106
120
|
for (const [coinName, poolPoint] of Object.entries(
|
|
107
121
|
parsedBorrowIncentivePoolData.poolPoints
|
|
108
122
|
)) {
|
|
109
|
-
const rewardCoinType =
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
123
|
+
const rewardCoinType = poolPoint.pointType;
|
|
124
|
+
let rewardCoinName = query.utils.parseCoinNameFromType(
|
|
125
|
+
rewardCoinType
|
|
126
|
+
) as SupportBorrowIncentiveRewardCoins;
|
|
127
|
+
// handle for scoin name
|
|
128
|
+
if (sCoinRawNameToName[rewardCoinName]) {
|
|
129
|
+
rewardCoinName = sCoinRawNameToName[rewardCoinName];
|
|
130
|
+
}
|
|
115
131
|
const rewardCoinDecimal = query.utils.getCoinDecimal(rewardCoinName);
|
|
132
|
+
const rewardCoinPrice = coinPrices?.[rewardCoinName] ?? 0;
|
|
116
133
|
|
|
117
134
|
const symbol = query.utils.parseSymbol(rewardCoinName);
|
|
118
135
|
const coinDecimal = query.utils.getCoinDecimal(rewardCoinName);
|
package/src/queries/coreQuery.ts
CHANGED
|
@@ -247,7 +247,7 @@ export const getMarketPools = async (
|
|
|
247
247
|
const marketObjectResponse = await query.cache.queryGetObject(marketId, {
|
|
248
248
|
showContent: true,
|
|
249
249
|
});
|
|
250
|
-
coinPrices = (await query.utils.getCoinPrices(
|
|
250
|
+
coinPrices = coinPrices ?? (await query.utils.getCoinPrices());
|
|
251
251
|
|
|
252
252
|
const marketPools: MarketPools = {};
|
|
253
253
|
|
|
@@ -305,9 +305,7 @@ export const getMarketPool = async (
|
|
|
305
305
|
marketObject?: SuiObjectData | null,
|
|
306
306
|
coinPrice?: number
|
|
307
307
|
): Promise<MarketPool | undefined> => {
|
|
308
|
-
coinPrice =
|
|
309
|
-
coinPrice ||
|
|
310
|
-
(await query.utils.getCoinPrices([poolCoinName]))?.[poolCoinName];
|
|
308
|
+
coinPrice = coinPrice ?? (await query.utils.getCoinPrices())?.[poolCoinName];
|
|
311
309
|
|
|
312
310
|
if (indexer) {
|
|
313
311
|
const marketPoolIndexer = await query.indexer.getMarketPool(poolCoinName);
|
|
@@ -536,8 +534,7 @@ export const getMarketCollaterals = async (
|
|
|
536
534
|
indexer: boolean = false
|
|
537
535
|
) => {
|
|
538
536
|
const marketId = query.address.get('core.market');
|
|
539
|
-
const coinPrices =
|
|
540
|
-
(await query.utils.getCoinPrices(collateralCoinNames)) ?? {};
|
|
537
|
+
const coinPrices = (await query.utils.getCoinPrices()) ?? {};
|
|
541
538
|
const marketCollaterals: MarketCollaterals = {};
|
|
542
539
|
|
|
543
540
|
if (indexer) {
|
|
@@ -595,10 +592,7 @@ export const getMarketCollateral = async (
|
|
|
595
592
|
coinPrice?: number
|
|
596
593
|
): Promise<MarketCollateral | undefined> => {
|
|
597
594
|
coinPrice =
|
|
598
|
-
coinPrice
|
|
599
|
-
(await query.utils.getCoinPrices([collateralCoinName]))?.[
|
|
600
|
-
collateralCoinName
|
|
601
|
-
];
|
|
595
|
+
coinPrice ?? (await query.utils.getCoinPrices())?.[collateralCoinName];
|
|
602
596
|
|
|
603
597
|
if (indexer) {
|
|
604
598
|
const marketCollateralIndexer =
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import BigNumber from 'bignumber.js';
|
|
2
2
|
import {
|
|
3
|
-
SUPPORT_BORROW_INCENTIVE_REWARDS,
|
|
4
3
|
SUPPORT_COLLATERALS,
|
|
5
4
|
SUPPORT_POOLS,
|
|
6
5
|
SUPPORT_SPOOLS,
|
|
@@ -50,7 +49,7 @@ export const getLendings = async (
|
|
|
50
49
|
(SUPPORT_SPOOLS as readonly SupportMarketCoins[]).includes(marketCoinName)
|
|
51
50
|
) as SupportStakeMarketCoins[];
|
|
52
51
|
|
|
53
|
-
const coinPrices = await query.utils.getCoinPrices(
|
|
52
|
+
const coinPrices = await query.utils.getCoinPrices();
|
|
54
53
|
const marketPools = await query.getMarketPools(poolCoinNames, {
|
|
55
54
|
indexer,
|
|
56
55
|
coinPrices,
|
|
@@ -124,9 +123,7 @@ export const getLending = async (
|
|
|
124
123
|
) => {
|
|
125
124
|
const marketCoinName = query.utils.parseMarketCoinName(poolCoinName);
|
|
126
125
|
coinPrice =
|
|
127
|
-
coinPrice ??
|
|
128
|
-
(await query.utils.getCoinPrices([poolCoinName]))?.[poolCoinName] ??
|
|
129
|
-
0;
|
|
126
|
+
coinPrice ?? (await query.utils.getCoinPrices())?.[poolCoinName] ?? 0;
|
|
130
127
|
|
|
131
128
|
marketPool =
|
|
132
129
|
marketPool ??
|
|
@@ -355,9 +352,9 @@ export const getObligationAccount = async (
|
|
|
355
352
|
const collateralAssetCoinNames: SupportCollateralCoins[] = [
|
|
356
353
|
...SUPPORT_COLLATERALS,
|
|
357
354
|
];
|
|
355
|
+
market = market ?? (await query.queryMarket({ indexer }));
|
|
358
356
|
coinPrices =
|
|
359
|
-
coinPrices ?? (await query.
|
|
360
|
-
market = market ?? (await query.queryMarket({ indexer, coinPrices }));
|
|
357
|
+
coinPrices ?? (await query.getAllCoinPrices({ marketPools: market.pools }));
|
|
361
358
|
coinAmounts =
|
|
362
359
|
coinAmounts ||
|
|
363
360
|
(await query.getCoinAmounts(collateralAssetCoinNames, ownerAddress));
|
|
@@ -526,64 +523,70 @@ export const getObligationAccount = async (
|
|
|
526
523
|
const borrowIncentivePool = borrowIncentivePools[coinName];
|
|
527
524
|
if (borrowIncentivePool) {
|
|
528
525
|
const rewards: ObligationBorrowIcentiveReward[] = [];
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
.plus(accountPoint.points)
|
|
550
|
-
);
|
|
551
|
-
availableClaimCoin = availableClaimAmount.shiftedBy(
|
|
552
|
-
-1 * poolPoint.coinDecimal
|
|
553
|
-
);
|
|
554
|
-
|
|
555
|
-
// for veSCA
|
|
556
|
-
const weightScale = BigNumber(1_000_000_000_000);
|
|
557
|
-
const boostValue = BigNumber(accountPoint.weightedAmount)
|
|
558
|
-
.div(
|
|
559
|
-
BigNumber(borrowIncentiveAccount.debtAmount)
|
|
560
|
-
.multipliedBy(poolPoint.baseWeight)
|
|
561
|
-
.dividedBy(weightScale)
|
|
562
|
-
)
|
|
563
|
-
.isFinite()
|
|
564
|
-
? BigNumber(accountPoint.weightedAmount)
|
|
565
|
-
.div(
|
|
566
|
-
BigNumber(borrowIncentiveAccount.debtAmount)
|
|
567
|
-
.multipliedBy(poolPoint.baseWeight)
|
|
568
|
-
.dividedBy(weightScale)
|
|
526
|
+
Object.entries(borrowIncentiveAccount.pointList).forEach(
|
|
527
|
+
([key, accountPoint]) => {
|
|
528
|
+
const poolPoint =
|
|
529
|
+
borrowIncentivePool.points[
|
|
530
|
+
key as SupportBorrowIncentiveRewardCoins
|
|
531
|
+
];
|
|
532
|
+
|
|
533
|
+
if (accountPoint && poolPoint) {
|
|
534
|
+
let availableClaimAmount = BigNumber(0);
|
|
535
|
+
let availableClaimCoin = BigNumber(0);
|
|
536
|
+
const accountBorrowedAmount = BigNumber(
|
|
537
|
+
accountPoint.weightedAmount
|
|
538
|
+
);
|
|
539
|
+
const baseIndexRate = 1_000_000_000;
|
|
540
|
+
const increasedPointRate = poolPoint.currentPointIndex
|
|
541
|
+
? Math.max(
|
|
542
|
+
BigNumber(poolPoint.currentPointIndex - accountPoint.index)
|
|
543
|
+
.dividedBy(baseIndexRate)
|
|
544
|
+
.toNumber(),
|
|
545
|
+
0
|
|
569
546
|
)
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
547
|
+
: 1;
|
|
548
|
+
availableClaimAmount = availableClaimAmount.plus(
|
|
549
|
+
accountBorrowedAmount
|
|
550
|
+
.multipliedBy(increasedPointRate)
|
|
551
|
+
.plus(accountPoint.points)
|
|
552
|
+
);
|
|
553
|
+
availableClaimCoin = availableClaimAmount.shiftedBy(
|
|
554
|
+
-1 * poolPoint.coinDecimal
|
|
555
|
+
);
|
|
556
|
+
|
|
557
|
+
// for veSCA
|
|
558
|
+
const weightScale = BigNumber(1_000_000_000_000);
|
|
559
|
+
const boostValue = BigNumber(accountPoint.weightedAmount)
|
|
560
|
+
.div(
|
|
561
|
+
BigNumber(borrowIncentiveAccount.debtAmount)
|
|
562
|
+
.multipliedBy(poolPoint.baseWeight)
|
|
563
|
+
.dividedBy(weightScale)
|
|
564
|
+
)
|
|
565
|
+
.isFinite()
|
|
566
|
+
? BigNumber(accountPoint.weightedAmount)
|
|
567
|
+
.div(
|
|
568
|
+
BigNumber(borrowIncentiveAccount.debtAmount)
|
|
569
|
+
.multipliedBy(poolPoint.baseWeight)
|
|
570
|
+
.dividedBy(weightScale)
|
|
571
|
+
)
|
|
572
|
+
.toNumber()
|
|
573
|
+
: 1;
|
|
574
|
+
|
|
575
|
+
if (availableClaimAmount.isGreaterThanOrEqualTo(0)) {
|
|
576
|
+
rewards.push({
|
|
577
|
+
coinName: poolPoint.coinName,
|
|
578
|
+
coinType: poolPoint.coinType,
|
|
579
|
+
symbol: poolPoint.symbol,
|
|
580
|
+
coinDecimal: poolPoint.coinDecimal,
|
|
581
|
+
coinPrice: poolPoint.coinPrice,
|
|
582
|
+
availableClaimAmount: availableClaimAmount.toNumber(),
|
|
583
|
+
availableClaimCoin: availableClaimCoin.toNumber(),
|
|
584
|
+
boostValue,
|
|
585
|
+
});
|
|
586
|
+
}
|
|
584
587
|
}
|
|
585
588
|
}
|
|
586
|
-
|
|
589
|
+
);
|
|
587
590
|
|
|
588
591
|
if (
|
|
589
592
|
Object.keys(borrowIncentivePool.points).some((coinName: any) => {
|
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
import { SuiObjectData } from '@mysten/sui/client';
|
|
2
|
-
import type { ScallopAddress } from '../models';
|
|
3
|
-
import type {
|
|
2
|
+
import type { ScallopAddress, ScallopQuery } from '../models';
|
|
3
|
+
import type {
|
|
4
|
+
CoinPrices,
|
|
5
|
+
MarketPools,
|
|
6
|
+
OptionalKeys,
|
|
7
|
+
SupportAssetCoins,
|
|
8
|
+
SupportSCoin,
|
|
9
|
+
} from '../types';
|
|
10
|
+
import { SUPPORT_SCOIN } from 'src/constants/common';
|
|
11
|
+
import BigNumber from 'bignumber.js';
|
|
4
12
|
|
|
5
13
|
/**
|
|
6
14
|
* Get price from pyth fee object.
|
|
@@ -126,3 +134,28 @@ export const getPythPrices = async (
|
|
|
126
134
|
{} as Record<SupportAssetCoins, number>
|
|
127
135
|
);
|
|
128
136
|
};
|
|
137
|
+
|
|
138
|
+
export const getAllCoinPrices = async (
|
|
139
|
+
query: ScallopQuery,
|
|
140
|
+
marketPools?: MarketPools,
|
|
141
|
+
coinPrices?: CoinPrices
|
|
142
|
+
) => {
|
|
143
|
+
coinPrices = coinPrices ?? (await query.utils.getCoinPrices());
|
|
144
|
+
marketPools =
|
|
145
|
+
marketPools ?? (await query.getMarketPools(undefined, { coinPrices }));
|
|
146
|
+
if (!marketPools) {
|
|
147
|
+
throw new Error(`Failed to fetch market pool for getAllCoinPrices`);
|
|
148
|
+
}
|
|
149
|
+
const sCoinPrices: OptionalKeys<Record<SupportSCoin, number>> = {};
|
|
150
|
+
SUPPORT_SCOIN.forEach((sCoinName) => {
|
|
151
|
+
const coinName = query.utils.parseCoinName(sCoinName);
|
|
152
|
+
sCoinPrices[sCoinName] = BigNumber(coinPrices[coinName] ?? 0)
|
|
153
|
+
.multipliedBy(marketPools[coinName]?.conversionRate ?? 1)
|
|
154
|
+
.toNumber();
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
return {
|
|
158
|
+
...coinPrices,
|
|
159
|
+
...sCoinPrices,
|
|
160
|
+
};
|
|
161
|
+
};
|
|
@@ -153,7 +153,7 @@ export const getSCoinSwapRate = async (
|
|
|
153
153
|
const BtoSCoinBRate = 1 / marketPools[1]!.conversionRate;
|
|
154
154
|
|
|
155
155
|
const calcAtoBRate = async () => {
|
|
156
|
-
const prices = await query.utils.getCoinPrices(
|
|
156
|
+
const prices = await query.utils.getCoinPrices();
|
|
157
157
|
if (!prices[fromCoinName] || !prices[toCoinName]) {
|
|
158
158
|
throw new Error('Failed to fetch the coin prices');
|
|
159
159
|
}
|
|
@@ -71,7 +71,6 @@ export const getSpools = async (
|
|
|
71
71
|
};
|
|
72
72
|
Object.values(spoolsIndexer).forEach(updateSpools);
|
|
73
73
|
|
|
74
|
-
// console.log(spools);
|
|
75
74
|
return spools;
|
|
76
75
|
}
|
|
77
76
|
|
|
@@ -122,7 +121,7 @@ export const getSpool = async (
|
|
|
122
121
|
`spool.pools.${marketCoinName}.rewardPoolId`
|
|
123
122
|
);
|
|
124
123
|
let spool: Spool | undefined = undefined;
|
|
125
|
-
coinPrices = coinPrices || (await query.utils.getCoinPrices(
|
|
124
|
+
coinPrices = coinPrices || (await query.utils.getCoinPrices());
|
|
126
125
|
|
|
127
126
|
if (indexer) {
|
|
128
127
|
const spoolIndexer = await query.indexer.getSpool(marketCoinName);
|
|
@@ -152,8 +151,7 @@ export const getSpool = async (
|
|
|
152
151
|
}
|
|
153
152
|
|
|
154
153
|
const rewardCoinName = query.utils.getSpoolRewardCoinName(marketCoinName);
|
|
155
|
-
coinPrices =
|
|
156
|
-
coinPrices || (await query.utils.getCoinPrices([coinName, rewardCoinName]));
|
|
154
|
+
coinPrices = coinPrices || (await query.utils.getCoinPrices());
|
|
157
155
|
|
|
158
156
|
const spoolObject = spoolObjectResponse[0];
|
|
159
157
|
const rewardPoolObject = spoolObjectResponse[1];
|
|
@@ -4,10 +4,7 @@ import type {
|
|
|
4
4
|
} from '@scallop-io/sui-kit';
|
|
5
5
|
import type { TransactionResult } from '@mysten/sui/transactions';
|
|
6
6
|
import type { ScallopBuilder } from '../../models';
|
|
7
|
-
import type {
|
|
8
|
-
SupportBorrowIncentiveCoins,
|
|
9
|
-
SupportBorrowIncentiveRewardCoins,
|
|
10
|
-
} from '../constant';
|
|
7
|
+
import type { SupportBorrowIncentiveRewardCoins } from '../constant';
|
|
11
8
|
|
|
12
9
|
export type BorrowIncentiveIds = {
|
|
13
10
|
borrowIncentivePkg: string;
|
|
@@ -35,7 +32,6 @@ export type BorrowIncentiveNormalMethods = {
|
|
|
35
32
|
claimBorrowIncentive: (
|
|
36
33
|
obligation: SuiObjectArg,
|
|
37
34
|
obligationKey: SuiObjectArg,
|
|
38
|
-
coinName: SupportBorrowIncentiveCoins,
|
|
39
35
|
rewardType: SupportBorrowIncentiveRewardCoins
|
|
40
36
|
) => TransactionResult;
|
|
41
37
|
deactivateBoost: (obligation: SuiObjectArg, veScaKey: SuiObjectArg) => void;
|
|
@@ -43,23 +39,22 @@ export type BorrowIncentiveNormalMethods = {
|
|
|
43
39
|
|
|
44
40
|
export type BorrowIncentiveQuickMethods = {
|
|
45
41
|
stakeObligationQuick(
|
|
46
|
-
obligation?:
|
|
47
|
-
obligationKey?:
|
|
42
|
+
obligation?: string,
|
|
43
|
+
obligationKey?: string
|
|
48
44
|
): Promise<void>;
|
|
49
45
|
stakeObligationWithVeScaQuick(
|
|
50
|
-
obligation?:
|
|
51
|
-
obligationKey?:
|
|
52
|
-
veScaKey?:
|
|
46
|
+
obligation?: string,
|
|
47
|
+
obligationKey?: string,
|
|
48
|
+
veScaKey?: string
|
|
53
49
|
): Promise<void>;
|
|
54
50
|
unstakeObligationQuick(
|
|
55
|
-
obligation?:
|
|
56
|
-
obligationKey?:
|
|
51
|
+
obligation?: string,
|
|
52
|
+
obligationKey?: string
|
|
57
53
|
): Promise<void>;
|
|
58
54
|
claimBorrowIncentiveQuick(
|
|
59
|
-
coinName: SupportBorrowIncentiveCoins,
|
|
60
55
|
rewardType: SupportBorrowIncentiveRewardCoins,
|
|
61
|
-
obligation?:
|
|
62
|
-
obligationKey?:
|
|
56
|
+
obligation?: string,
|
|
57
|
+
obligationKey?: string
|
|
63
58
|
): Promise<TransactionResult>;
|
|
64
59
|
};
|
|
65
60
|
|
|
@@ -23,8 +23,7 @@ export type SupportCoins =
|
|
|
23
23
|
export type SupportAssetCoins =
|
|
24
24
|
| SupportPoolCoins
|
|
25
25
|
| SupportCollateralCoins
|
|
26
|
-
| SupportStakeRewardCoins
|
|
27
|
-
| SupportBorrowIncentiveRewardCoins;
|
|
26
|
+
| SupportStakeRewardCoins;
|
|
28
27
|
export type SupportPoolCoins = (typeof SUPPORT_POOLS)[number];
|
|
29
28
|
export type SupportCollateralCoins = (typeof SUPPORT_COLLATERALS)[number];
|
|
30
29
|
export type SupportMarketCoins =
|
package/src/types/utils.ts
CHANGED
|
@@ -1,18 +1,10 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { SupportCoins } from './constant';
|
|
2
2
|
|
|
3
3
|
export type OptionalKeys<T> = {
|
|
4
4
|
[K in keyof T]?: T[K];
|
|
5
5
|
};
|
|
6
6
|
|
|
7
|
-
export type CoinPrices = OptionalKeys<Record<
|
|
8
|
-
|
|
9
|
-
export type PriceMap = Map<
|
|
10
|
-
SupportAssetCoins,
|
|
11
|
-
{
|
|
12
|
-
price: number;
|
|
13
|
-
publishTime: number;
|
|
14
|
-
}
|
|
15
|
-
>;
|
|
7
|
+
export type CoinPrices = OptionalKeys<Record<SupportCoins, number>>;
|
|
16
8
|
|
|
17
9
|
export type PoolAddressInfo = {
|
|
18
10
|
name: string;
|
package/src/utils/query.ts
CHANGED
|
@@ -546,93 +546,6 @@ export const calculateBorrowIncentivePoolPointData = (
|
|
|
546
546
|
};
|
|
547
547
|
};
|
|
548
548
|
|
|
549
|
-
// /**
|
|
550
|
-
// * Parse origin borrow incentive reward pool data to a more readable format.
|
|
551
|
-
// *
|
|
552
|
-
// * @param originBorrowIncentiveRewardPoolData - Origin borrow incentive reward pool data
|
|
553
|
-
// * @return Parsed borrow incentive reward pool data
|
|
554
|
-
// */
|
|
555
|
-
// export const parseOriginBorrowIncentiveRewardPoolData = (
|
|
556
|
-
// originBorrowIncentiveRewardPoolData: OriginBorrowIncentiveRewardPoolData
|
|
557
|
-
// ): ParsedBorrowIncentiveRewardPoolData => {
|
|
558
|
-
// return {
|
|
559
|
-
// rewardType: normalizeStructTag(
|
|
560
|
-
// originBorrowIncentiveRewardPoolData.reward_type.name
|
|
561
|
-
// ),
|
|
562
|
-
// claimedRewards: Number(originBorrowIncentiveRewardPoolData.claimed_rewards),
|
|
563
|
-
// exchangeRateNumerator: Number(
|
|
564
|
-
// originBorrowIncentiveRewardPoolData.exchange_rate_numerator
|
|
565
|
-
// ),
|
|
566
|
-
// exchangeRateDenominator: Number(
|
|
567
|
-
// originBorrowIncentiveRewardPoolData.exchange_rate_denominator
|
|
568
|
-
// ),
|
|
569
|
-
// remainingRewards: Number(
|
|
570
|
-
// originBorrowIncentiveRewardPoolData.remaining_reward
|
|
571
|
-
// ),
|
|
572
|
-
// };
|
|
573
|
-
// };
|
|
574
|
-
|
|
575
|
-
// export const calculateBorrowIncentiveRewardPoolData = (
|
|
576
|
-
// parsedBorrowIncentivePoolData: ParsedBorrowIncentivePoolData,
|
|
577
|
-
// parsedBorrowIncentiveRewardPoolData: ParsedBorrowIncentiveRewardPoolData,
|
|
578
|
-
// calculatedBorrowIncentivePoolData: CalculatedBorrowIncentivePoolData,
|
|
579
|
-
// rewardCoinPrice: number,
|
|
580
|
-
// rewardCoinDecimal: number
|
|
581
|
-
// ): CalculatedBorrowIncentiveRewardPoolData => {
|
|
582
|
-
// const rateYearFactor = 365 * 24 * 60 * 60;
|
|
583
|
-
|
|
584
|
-
// const rewardPerSec = BigNumber(
|
|
585
|
-
// calculatedBorrowIncentivePoolData.distributedPointPerSec
|
|
586
|
-
// )
|
|
587
|
-
// .multipliedBy(parsedBorrowIncentiveRewardPoolData.exchangeRateNumerator)
|
|
588
|
-
// .dividedBy(parsedBorrowIncentiveRewardPoolData.exchangeRateDenominator);
|
|
589
|
-
// const totalRewardAmount = BigNumber(parsedBorrowIncentivePoolData.maxPoint)
|
|
590
|
-
// .multipliedBy(parsedBorrowIncentiveRewardPoolData.exchangeRateNumerator)
|
|
591
|
-
// .dividedBy(parsedBorrowIncentiveRewardPoolData.exchangeRateDenominator);
|
|
592
|
-
// const totalRewardCoin = totalRewardAmount.shiftedBy(-1 * rewardCoinDecimal);
|
|
593
|
-
// const totalRewardValue = totalRewardCoin.multipliedBy(rewardCoinPrice);
|
|
594
|
-
// const remaindRewardAmount = BigNumber(
|
|
595
|
-
// parsedBorrowIncentiveRewardPoolData.remainingRewards
|
|
596
|
-
// );
|
|
597
|
-
// const remaindRewardCoin = remaindRewardAmount.shiftedBy(
|
|
598
|
-
// -1 * rewardCoinDecimal
|
|
599
|
-
// );
|
|
600
|
-
// const remaindRewardValue = remaindRewardCoin.multipliedBy(rewardCoinPrice);
|
|
601
|
-
// const claimedRewardAmount = BigNumber(
|
|
602
|
-
// parsedBorrowIncentiveRewardPoolData.claimedRewards
|
|
603
|
-
// );
|
|
604
|
-
// const claimedRewardCoin = claimedRewardAmount.shiftedBy(
|
|
605
|
-
// -1 * rewardCoinDecimal
|
|
606
|
-
// );
|
|
607
|
-
// const claimedRewardValue = claimedRewardCoin.multipliedBy(rewardCoinPrice);
|
|
608
|
-
|
|
609
|
-
// const rewardValueForYear = BigNumber(rewardPerSec)
|
|
610
|
-
// .shiftedBy(-1 * rewardCoinDecimal)
|
|
611
|
-
// .multipliedBy(rateYearFactor)
|
|
612
|
-
// .multipliedBy(rewardCoinPrice);
|
|
613
|
-
// const rewardRate = rewardValueForYear
|
|
614
|
-
// .dividedBy(calculatedBorrowIncentivePoolData.stakedValue)
|
|
615
|
-
// .isFinite()
|
|
616
|
-
// ? rewardValueForYear
|
|
617
|
-
// .dividedBy(calculatedBorrowIncentivePoolData.stakedValue)
|
|
618
|
-
// .toNumber()
|
|
619
|
-
// : Infinity;
|
|
620
|
-
|
|
621
|
-
// return {
|
|
622
|
-
// rewardApr: rewardRate,
|
|
623
|
-
// totalRewardAmount: totalRewardAmount.toNumber(),
|
|
624
|
-
// totalRewardCoin: totalRewardCoin.toNumber(),
|
|
625
|
-
// totalRewardValue: totalRewardValue.toNumber(),
|
|
626
|
-
// remaindRewardAmount: remaindRewardAmount.toNumber(),
|
|
627
|
-
// remaindRewardCoin: remaindRewardCoin.toNumber(),
|
|
628
|
-
// remaindRewardValue: remaindRewardValue.toNumber(),
|
|
629
|
-
// claimedRewardAmount: claimedRewardAmount.toNumber(),
|
|
630
|
-
// claimedRewardCoin: claimedRewardCoin.toNumber(),
|
|
631
|
-
// claimedRewardValue: claimedRewardValue.toNumber(),
|
|
632
|
-
// rewardPerSec: rewardPerSec.toNumber(),
|
|
633
|
-
// };
|
|
634
|
-
// };
|
|
635
|
-
|
|
636
549
|
export const parseOriginBorrowIncentiveAccountPoolPointData = (
|
|
637
550
|
originBorrowIncentiveAccountPoolPointData: OriginBorrowIncentiveAccountPoolData
|
|
638
551
|
): ParsedBorrowIncentiveAccountPoolData => {
|