@scallop-io/sui-scallop-sdk 0.46.3 → 0.46.32
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 +104 -88
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +104 -88
- package/dist/index.mjs.map +1 -1
- package/dist/types/query/borrowIncentive.d.ts +3 -4
- package/dist/utils/query.d.ts +1 -1
- package/package.json +3 -2
- package/src/builders/vescaBuilder.ts +0 -5
- package/src/models/scallopIndexer.ts +16 -0
- package/src/queries/borrowIncentiveQuery.ts +33 -27
- package/src/queries/portfolioQuery.ts +13 -11
- package/src/types/query/borrowIncentive.ts +3 -4
- package/src/utils/query.ts +1 -9
|
@@ -20,7 +20,9 @@ export type BorrowIncentivePool = {
|
|
|
20
20
|
coinType: string;
|
|
21
21
|
coinDecimal: number;
|
|
22
22
|
coinPrice: number;
|
|
23
|
-
|
|
23
|
+
stakedAmount: number;
|
|
24
|
+
stakedCoin: number;
|
|
25
|
+
stakedValue: number;
|
|
24
26
|
points: OptionalKeys<Record<SupportBorrowIncentiveRewardCoins, BorrowIncentivePoolPoints>>;
|
|
25
27
|
};
|
|
26
28
|
export type OriginBorrowIncentivePoolPointData = {
|
|
@@ -66,9 +68,6 @@ export type ParsedBorrowIncentivePoolData = {
|
|
|
66
68
|
createdAt: number;
|
|
67
69
|
};
|
|
68
70
|
export type CalculatedBorrowIncentivePoolPointData = {
|
|
69
|
-
stakedAmount: number;
|
|
70
|
-
stakedCoin: number;
|
|
71
|
-
stakedValue: number;
|
|
72
71
|
baseWeight: number;
|
|
73
72
|
weightedStakedAmount: number;
|
|
74
73
|
weightedStakedCoin: number;
|
package/dist/utils/query.d.ts
CHANGED
|
@@ -41,7 +41,7 @@ export declare const parseOriginBorrowIncentivesPoolPointData: (originBorrowInce
|
|
|
41
41
|
* @return Parsed borrow incentive pool data
|
|
42
42
|
*/
|
|
43
43
|
export declare const parseOriginBorrowIncentivePoolData: (originBorrowIncentivePoolData: OriginBorrowIncentivePoolData) => ParsedBorrowIncentivePoolData;
|
|
44
|
-
export declare const calculateBorrowIncentivePoolPointData: (
|
|
44
|
+
export declare const calculateBorrowIncentivePoolPointData: (parsedBorrowIncentivePoolData: ParsedBorrowIncentivePoolData, parsedBorrowIncentivePoolPointData: ParsedBorrowIncentivePoolPointData, rewardCoinPrice: number, rewardCoinDecimal: number, poolCoinPrice: number, poolCoinDecimal: number) => CalculatedBorrowIncentivePoolPointData;
|
|
45
45
|
export declare const parseOriginBorrowIncentiveAccountPoolPointData: (originBorrowIncentiveAccountPoolPointData: OriginBorrowIncentiveAccountPoolData) => ParsedBorrowIncentiveAccountPoolData;
|
|
46
46
|
/**
|
|
47
47
|
* Parse origin borrow incentive account data to a more readable format.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@scallop-io/sui-scallop-sdk",
|
|
3
|
-
"version": "0.46.
|
|
3
|
+
"version": "0.46.32",
|
|
4
4
|
"description": "Typescript sdk for interacting with Scallop contract on SUI",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sui",
|
|
@@ -76,7 +76,8 @@
|
|
|
76
76
|
},
|
|
77
77
|
"peerDependencies": {
|
|
78
78
|
"@mysten/sui.js": "0.49.1",
|
|
79
|
-
"@scallop-io/sui-kit": "^0.44.2"
|
|
79
|
+
"@scallop-io/sui-kit": "^0.44.2",
|
|
80
|
+
"bn.js": "^5.2.1"
|
|
80
81
|
},
|
|
81
82
|
"lint-staged": {
|
|
82
83
|
"**/*.ts": [
|
|
@@ -219,11 +219,6 @@ const generateQuickVeScaMethod: GenerateVeScaQuickMethod = ({
|
|
|
219
219
|
newUnlockAt,
|
|
220
220
|
veSca?.unlockAt
|
|
221
221
|
);
|
|
222
|
-
console.log(
|
|
223
|
-
new Date(newUnlockAt * 1000).toLocaleString('en-CA', {
|
|
224
|
-
hour12: true,
|
|
225
|
-
})
|
|
226
|
-
);
|
|
227
222
|
|
|
228
223
|
const isInitialLock = !veSca?.unlockAt;
|
|
229
224
|
const isLockExpired =
|
|
@@ -18,6 +18,8 @@ import type {
|
|
|
18
18
|
ScallopQueryParams,
|
|
19
19
|
ScallopParams,
|
|
20
20
|
ScallopInstanceParams,
|
|
21
|
+
BorrowIncentivePoolPoints,
|
|
22
|
+
SupportBorrowIncentiveRewardCoins,
|
|
21
23
|
} from '../types';
|
|
22
24
|
import { ScallopCache } from './scallopCache';
|
|
23
25
|
|
|
@@ -185,6 +187,20 @@ export class ScallopIndexer {
|
|
|
185
187
|
if (response.status === 200) {
|
|
186
188
|
return response.data.borrowIncentivePools.reduce(
|
|
187
189
|
(borrowIncentivePools, borrowIncentivePool) => {
|
|
190
|
+
if (Array.isArray(borrowIncentivePool.points)) {
|
|
191
|
+
borrowIncentivePool.points = (
|
|
192
|
+
borrowIncentivePool.points as BorrowIncentivePoolPoints[]
|
|
193
|
+
).reduce(
|
|
194
|
+
(prev, curr) => {
|
|
195
|
+
prev[curr.coinName] = curr;
|
|
196
|
+
return prev;
|
|
197
|
+
},
|
|
198
|
+
{} as Record<
|
|
199
|
+
SupportBorrowIncentiveRewardCoins,
|
|
200
|
+
BorrowIncentivePoolPoints
|
|
201
|
+
>
|
|
202
|
+
);
|
|
203
|
+
}
|
|
188
204
|
borrowIncentivePools[borrowIncentivePool.coinName] =
|
|
189
205
|
borrowIncentivePool;
|
|
190
206
|
return borrowIncentivePools;
|
|
@@ -19,6 +19,7 @@ import type {
|
|
|
19
19
|
BorrowIncentivePoolPoints,
|
|
20
20
|
OptionalKeys,
|
|
21
21
|
} from '../types';
|
|
22
|
+
import BigNumber from 'bignumber.js';
|
|
22
23
|
|
|
23
24
|
/**
|
|
24
25
|
* Query borrow incentive pools data.
|
|
@@ -47,41 +48,40 @@ export const queryBorrowIncentivePools = async (
|
|
|
47
48
|
|
|
48
49
|
const borrowIncentivePools: BorrowIncentivePools = {};
|
|
49
50
|
|
|
51
|
+
const coinPrices = await query.utils.getCoinPrices(
|
|
52
|
+
[
|
|
53
|
+
...new Set([
|
|
54
|
+
...borrowIncentiveCoinNames,
|
|
55
|
+
...SUPPORT_BORROW_INCENTIVE_REWARDS,
|
|
56
|
+
]),
|
|
57
|
+
] ?? []
|
|
58
|
+
);
|
|
59
|
+
|
|
50
60
|
if (indexer) {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
// return borrowIncentivePools;
|
|
61
|
+
const borrowIncentivePoolsIndexer =
|
|
62
|
+
await query.indexer.getBorrowIncentivePools();
|
|
63
|
+
for (const borrowIncentivePool of Object.values(
|
|
64
|
+
borrowIncentivePoolsIndexer
|
|
65
|
+
)) {
|
|
66
|
+
if (!borrowIncentiveCoinNames.includes(borrowIncentivePool.coinName))
|
|
67
|
+
continue;
|
|
68
|
+
borrowIncentivePool.coinPrice =
|
|
69
|
+
coinPrices[borrowIncentivePool.coinName] ||
|
|
70
|
+
borrowIncentivePool.coinPrice;
|
|
71
|
+
// borrowIncentivePool.rewardCoinPrice =
|
|
72
|
+
// coinPrices[rewardCoinName] || borrowIncentivePool.rewardCoinPrice;
|
|
73
|
+
borrowIncentivePools[borrowIncentivePool.coinName] = borrowIncentivePool;
|
|
74
|
+
}
|
|
75
|
+
return borrowIncentivePools;
|
|
67
76
|
}
|
|
68
77
|
|
|
69
78
|
for (const pool of borrowIncentivePoolsQueryData.incentive_pools) {
|
|
70
79
|
const borrowIncentivePoolPoints: OptionalKeys<
|
|
71
|
-
Record<
|
|
80
|
+
Record<SupportBorrowIncentiveRewardCoins, BorrowIncentivePoolPoints>
|
|
72
81
|
> = {};
|
|
73
82
|
const parsedBorrowIncentivePoolData =
|
|
74
83
|
parseOriginBorrowIncentivePoolData(pool);
|
|
75
84
|
|
|
76
|
-
const coinPrices = await query.utils.getCoinPrices(
|
|
77
|
-
[
|
|
78
|
-
...new Set([
|
|
79
|
-
...borrowIncentiveCoinNames,
|
|
80
|
-
...SUPPORT_BORROW_INCENTIVE_REWARDS,
|
|
81
|
-
]),
|
|
82
|
-
] ?? []
|
|
83
|
-
);
|
|
84
|
-
|
|
85
85
|
const poolCoinType = normalizeStructTag(pool.pool_type.name);
|
|
86
86
|
const poolCoinName =
|
|
87
87
|
query.utils.parseCoinNameFromType<SupportBorrowIncentiveCoins>(
|
|
@@ -133,14 +133,20 @@ export const queryBorrowIncentivePools = async (
|
|
|
133
133
|
};
|
|
134
134
|
}
|
|
135
135
|
|
|
136
|
+
const stakedAmount = BigNumber(parsedBorrowIncentivePoolData.staked);
|
|
137
|
+
const stakedCoin = stakedAmount.shiftedBy(-1 * poolCoinDecimal);
|
|
138
|
+
const stakedValue = stakedCoin.multipliedBy(poolCoinPrice);
|
|
139
|
+
|
|
136
140
|
borrowIncentivePools[poolCoinName] = {
|
|
137
141
|
coinName: poolCoinName,
|
|
138
142
|
symbol: query.utils.parseSymbol(poolCoinName),
|
|
139
143
|
coinType: poolCoinType,
|
|
140
144
|
coinDecimal: poolCoinDecimal,
|
|
141
145
|
coinPrice: poolCoinPrice,
|
|
146
|
+
stakedAmount: stakedAmount.toNumber(),
|
|
147
|
+
stakedCoin: stakedCoin.toNumber(),
|
|
148
|
+
stakedValue: stakedValue.toNumber(),
|
|
142
149
|
points: borrowIncentivePoolPoints,
|
|
143
|
-
staked: parsedBorrowIncentivePoolData.staked,
|
|
144
150
|
};
|
|
145
151
|
}
|
|
146
152
|
|
|
@@ -280,17 +280,19 @@ export const getObligationAccounts = async (
|
|
|
280
280
|
const obligations = await query.getObligations(ownerAddress);
|
|
281
281
|
|
|
282
282
|
const obligationAccounts: ObligationAccounts = {};
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
283
|
+
await Promise.allSettled(
|
|
284
|
+
obligations.map(async (obligation) => {
|
|
285
|
+
obligationAccounts[obligation.keyId] = await getObligationAccount(
|
|
286
|
+
query,
|
|
287
|
+
obligation.id,
|
|
288
|
+
ownerAddress,
|
|
289
|
+
indexer,
|
|
290
|
+
market,
|
|
291
|
+
coinPrices,
|
|
292
|
+
coinAmounts
|
|
293
|
+
);
|
|
294
|
+
})
|
|
295
|
+
);
|
|
294
296
|
|
|
295
297
|
return obligationAccounts;
|
|
296
298
|
};
|
|
@@ -36,7 +36,9 @@ export type BorrowIncentivePool = {
|
|
|
36
36
|
coinType: string;
|
|
37
37
|
coinDecimal: number;
|
|
38
38
|
coinPrice: number;
|
|
39
|
-
|
|
39
|
+
stakedAmount: number;
|
|
40
|
+
stakedCoin: number;
|
|
41
|
+
stakedValue: number;
|
|
40
42
|
points: OptionalKeys<
|
|
41
43
|
Record<SupportBorrowIncentiveRewardCoins, BorrowIncentivePoolPoints>
|
|
42
44
|
>;
|
|
@@ -94,9 +96,6 @@ export type ParsedBorrowIncentivePoolData = {
|
|
|
94
96
|
};
|
|
95
97
|
|
|
96
98
|
export type CalculatedBorrowIncentivePoolPointData = {
|
|
97
|
-
stakedAmount: number;
|
|
98
|
-
stakedCoin: number;
|
|
99
|
-
stakedValue: number;
|
|
100
99
|
baseWeight: number;
|
|
101
100
|
weightedStakedAmount: number;
|
|
102
101
|
weightedStakedCoin: number;
|
package/src/utils/query.ts
CHANGED
|
@@ -447,7 +447,7 @@ export const parseOriginBorrowIncentivePoolData = (
|
|
|
447
447
|
};
|
|
448
448
|
|
|
449
449
|
export const calculateBorrowIncentivePoolPointData = (
|
|
450
|
-
|
|
450
|
+
parsedBorrowIncentivePoolData: ParsedBorrowIncentivePoolData,
|
|
451
451
|
parsedBorrowIncentivePoolPointData: ParsedBorrowIncentivePoolPointData,
|
|
452
452
|
rewardCoinPrice: number,
|
|
453
453
|
rewardCoinDecimal: number,
|
|
@@ -488,11 +488,6 @@ export const calculateBorrowIncentivePoolPointData = (
|
|
|
488
488
|
parsedBorrowIncentivePoolPointData.distributedPoint
|
|
489
489
|
).plus(accumulatedPoints);
|
|
490
490
|
|
|
491
|
-
// pure staked amount
|
|
492
|
-
const stakedAmount = BigNumber(pasredBorrowIncentinvePoolData.staked);
|
|
493
|
-
|
|
494
|
-
const stakedCoin = stakedAmount.shiftedBy(-1 * poolCoinDecimal);
|
|
495
|
-
const stakedValue = stakedCoin.multipliedBy(poolCoinPrice);
|
|
496
491
|
const baseWeight = BigNumber(parsedBorrowIncentivePoolPointData.baseWeight);
|
|
497
492
|
|
|
498
493
|
// staked amount applied with weight
|
|
@@ -539,9 +534,6 @@ export const calculateBorrowIncentivePoolPointData = (
|
|
|
539
534
|
accumulatedPoints: accumulatedPoints.toNumber(),
|
|
540
535
|
currentPointIndex: currentPointIndex.toNumber(),
|
|
541
536
|
currentTotalDistributedPoint: currentTotalDistributedPoint.toNumber(),
|
|
542
|
-
stakedAmount: stakedAmount.toNumber(),
|
|
543
|
-
stakedCoin: stakedCoin.toNumber(),
|
|
544
|
-
stakedValue: stakedValue.toNumber(),
|
|
545
537
|
baseWeight: baseWeight.toNumber(),
|
|
546
538
|
weightedStakedAmount: weightedStakedAmount.toNumber(),
|
|
547
539
|
weightedStakedCoin: weightedStakedCoin.toNumber(),
|