@scallop-io/sui-scallop-sdk 0.44.18 → 0.44.19
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 +7 -0
- package/dist/builders/vescaBuilder.d.ts +24 -0
- package/dist/constants/common.d.ts +7 -4
- package/dist/constants/index.d.ts +1 -0
- package/dist/constants/vesca.d.ts +5 -0
- package/dist/index.js +874 -254
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +863 -247
- package/dist/index.mjs.map +1 -1
- package/dist/models/scallopClient.d.ts +7 -7
- package/dist/models/scallopUtils.d.ts +16 -14
- package/dist/queries/index.d.ts +1 -0
- package/dist/queries/vescaQuery.d.ts +28 -0
- package/dist/types/address.d.ts +9 -0
- package/dist/types/builder/borrowIncentive.d.ts +9 -6
- package/dist/types/builder/index.d.ts +3 -1
- package/dist/types/builder/vesca.d.ts +33 -0
- package/dist/types/constant/enum.d.ts +1 -1
- package/dist/types/query/borrowIncentive.d.ts +65 -60
- package/dist/types/query/index.d.ts +1 -0
- package/dist/types/query/portfolio.d.ts +12 -6
- package/dist/types/query/vesca.d.ts +7 -0
- package/dist/types/utils.d.ts +1 -2
- package/dist/utils/builder.d.ts +6 -0
- package/dist/utils/query.d.ts +4 -10
- package/dist/utils/util.d.ts +7 -0
- package/package.json +1 -1
- package/src/builders/borrowIncentiveBuilder.ts +174 -25
- package/src/builders/index.ts +6 -2
- package/src/builders/vescaBuilder.ts +392 -0
- package/src/constants/common.ts +19 -6
- package/src/constants/enum.ts +9 -3
- package/src/constants/index.ts +1 -0
- package/src/constants/vesca.ts +7 -0
- package/src/models/scallopAddress.ts +9 -1
- package/src/models/scallopClient.ts +29 -20
- package/src/models/scallopUtils.ts +45 -0
- package/src/queries/borrowIncentiveQuery.ts +93 -83
- package/src/queries/coreQuery.ts +19 -20
- package/src/queries/index.ts +1 -0
- package/src/queries/portfolioQuery.ts +79 -41
- package/src/queries/spoolQuery.ts +1 -1
- package/src/queries/vescaQuery.ts +124 -0
- package/src/types/address.ts +9 -0
- package/src/types/builder/borrowIncentive.ts +22 -5
- package/src/types/builder/index.ts +4 -1
- package/src/types/builder/vesca.ts +73 -0
- package/src/types/constant/enum.ts +1 -1
- package/src/types/query/borrowIncentive.ts +195 -74
- package/src/types/query/index.ts +1 -0
- package/src/types/query/portfolio.ts +17 -6
- package/src/types/query/vesca.ts +7 -0
- package/src/types/utils.ts +1 -1
- package/src/utils/builder.ts +141 -0
- package/src/utils/query.ts +221 -130
- package/src/utils/util.ts +28 -0
package/src/utils/query.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import BigNumber from 'bignumber.js';
|
|
2
|
-
import { normalizeStructTag } from '@mysten/sui.js/utils';
|
|
2
|
+
import { normalizeStructTag, parseStructTag } from '@mysten/sui.js/utils';
|
|
3
3
|
import type { ScallopUtils } from '../models';
|
|
4
4
|
import type {
|
|
5
5
|
OriginMarketPoolData,
|
|
@@ -16,14 +16,16 @@ import type {
|
|
|
16
16
|
CalculatedSpoolRewardPoolData,
|
|
17
17
|
OriginBorrowIncentivePoolData,
|
|
18
18
|
ParsedBorrowIncentivePoolData,
|
|
19
|
-
CalculatedBorrowIncentivePoolData,
|
|
20
|
-
OriginBorrowIncentiveRewardPoolData,
|
|
21
|
-
ParsedBorrowIncentiveRewardPoolData,
|
|
22
|
-
CalculatedBorrowIncentiveRewardPoolData,
|
|
23
19
|
OriginBorrowIncentiveAccountData,
|
|
24
20
|
ParsedBorrowIncentiveAccountData,
|
|
25
21
|
SupportPoolCoins,
|
|
26
22
|
SupportCollateralCoins,
|
|
23
|
+
OriginBorrowIncentivePoolPointData,
|
|
24
|
+
ParsedBorrowIncentivePoolPointData,
|
|
25
|
+
CalculatedBorrowIncentivePoolPointData,
|
|
26
|
+
OriginBorrowIncentiveAccountPoolData,
|
|
27
|
+
ParsedBorrowIncentiveAccountPoolData,
|
|
28
|
+
SupportBorrowIncentiveRewardCoins,
|
|
27
29
|
} from '../types';
|
|
28
30
|
|
|
29
31
|
/**
|
|
@@ -385,6 +387,28 @@ export const calculateSpoolRewardPoolData = (
|
|
|
385
387
|
};
|
|
386
388
|
};
|
|
387
389
|
|
|
390
|
+
export const parseOriginBorrowIncentivesPoolPointData = (
|
|
391
|
+
originBorrowIncentivePoolPointData: OriginBorrowIncentivePoolPointData
|
|
392
|
+
): ParsedBorrowIncentivePoolPointData => {
|
|
393
|
+
return {
|
|
394
|
+
pointType: normalizeStructTag(
|
|
395
|
+
originBorrowIncentivePoolPointData.point_type.name
|
|
396
|
+
),
|
|
397
|
+
distributedPointPerPeriod: Number(
|
|
398
|
+
originBorrowIncentivePoolPointData.distributed_point_per_period
|
|
399
|
+
),
|
|
400
|
+
period: Number(originBorrowIncentivePoolPointData.point_distribution_time),
|
|
401
|
+
distributedPoint: Number(
|
|
402
|
+
originBorrowIncentivePoolPointData.distributed_point
|
|
403
|
+
),
|
|
404
|
+
points: Number(originBorrowIncentivePoolPointData.points),
|
|
405
|
+
index: Number(originBorrowIncentivePoolPointData.index),
|
|
406
|
+
baseWeight: Number(originBorrowIncentivePoolPointData.base_weight),
|
|
407
|
+
weightedAmount: Number(originBorrowIncentivePoolPointData.weighted_amount),
|
|
408
|
+
lastUpdate: Number(originBorrowIncentivePoolPointData.last_update),
|
|
409
|
+
};
|
|
410
|
+
};
|
|
411
|
+
|
|
388
412
|
/**
|
|
389
413
|
* Parse origin borrow incentive pool data to a more readable format.
|
|
390
414
|
*
|
|
@@ -396,174 +420,230 @@ export const parseOriginBorrowIncentivePoolData = (
|
|
|
396
420
|
): ParsedBorrowIncentivePoolData => {
|
|
397
421
|
return {
|
|
398
422
|
poolType: normalizeStructTag(originBorrowIncentivePoolData.pool_type.name),
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
pointPerPeriod: Number(
|
|
402
|
-
originBorrowIncentivePoolData.distributed_point_per_period
|
|
403
|
-
),
|
|
404
|
-
period: Number(originBorrowIncentivePoolData.point_distribution_time),
|
|
405
|
-
maxStake: Number(originBorrowIncentivePoolData.max_stakes),
|
|
423
|
+
minStakes: Number(originBorrowIncentivePoolData.min_stakes),
|
|
424
|
+
maxStakes: Number(originBorrowIncentivePoolData.max_stakes),
|
|
406
425
|
staked: Number(originBorrowIncentivePoolData.stakes),
|
|
407
|
-
index: Number(originBorrowIncentivePoolData.index),
|
|
408
426
|
createdAt: Number(originBorrowIncentivePoolData.created_at),
|
|
409
|
-
|
|
427
|
+
poolPoints: originBorrowIncentivePoolData.points.reduce(
|
|
428
|
+
(acc, point) => {
|
|
429
|
+
const parsed = parseOriginBorrowIncentivesPoolPointData(point);
|
|
430
|
+
const name = parseStructTag(
|
|
431
|
+
parsed.pointType
|
|
432
|
+
).name.toLowerCase() as SupportBorrowIncentiveRewardCoins;
|
|
433
|
+
acc[name] = parsed;
|
|
434
|
+
return acc;
|
|
435
|
+
},
|
|
436
|
+
{} as Record<
|
|
437
|
+
SupportBorrowIncentiveRewardCoins,
|
|
438
|
+
ParsedBorrowIncentivePoolPointData
|
|
439
|
+
>
|
|
440
|
+
),
|
|
410
441
|
};
|
|
411
442
|
};
|
|
412
443
|
|
|
413
|
-
export const
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
444
|
+
export const calculateBorrowIncentivePoolPointData = (
|
|
445
|
+
pasredBorrowIncentinvePoolData: ParsedBorrowIncentivePoolData,
|
|
446
|
+
parsedBorrowIncentivePoolPointData: ParsedBorrowIncentivePoolPointData,
|
|
447
|
+
rewardCoinPrice: number,
|
|
448
|
+
rewardCoinDecimal: number,
|
|
449
|
+
poolCoinPrice: number,
|
|
450
|
+
poolCoinDecimal: number
|
|
451
|
+
): CalculatedBorrowIncentivePoolPointData => {
|
|
418
452
|
const baseIndexRate = 1_000_000_000;
|
|
419
453
|
|
|
420
454
|
const distributedPointPerSec = BigNumber(
|
|
421
|
-
|
|
422
|
-
).dividedBy(
|
|
423
|
-
|
|
424
|
-
const pointPerSec = BigNumber(
|
|
425
|
-
parsedBorrowIncentivePoolData.pointPerPeriod
|
|
426
|
-
).dividedBy(parsedBorrowIncentivePoolData.period);
|
|
427
|
-
const remainingPeriod = BigNumber(parsedBorrowIncentivePoolData.maxPoint)
|
|
428
|
-
.minus(parsedBorrowIncentivePoolData.distributedPoint)
|
|
429
|
-
.dividedBy(pointPerSec);
|
|
430
|
-
const startDate = parsedBorrowIncentivePoolData.createdAt;
|
|
431
|
-
const endDate = remainingPeriod
|
|
432
|
-
.plus(parsedBorrowIncentivePoolData.lastUpdate)
|
|
433
|
-
.integerValue()
|
|
434
|
-
.toNumber();
|
|
455
|
+
parsedBorrowIncentivePoolPointData.distributedPointPerPeriod
|
|
456
|
+
).dividedBy(parsedBorrowIncentivePoolPointData.period);
|
|
435
457
|
|
|
436
458
|
const timeDelta = BigNumber(
|
|
437
459
|
Math.floor(new Date().getTime() / 1000) -
|
|
438
|
-
|
|
460
|
+
parsedBorrowIncentivePoolPointData.lastUpdate
|
|
439
461
|
)
|
|
440
|
-
.dividedBy(
|
|
462
|
+
.dividedBy(parsedBorrowIncentivePoolPointData.period)
|
|
441
463
|
.toFixed(0);
|
|
442
|
-
const remainingPoints = BigNumber(
|
|
443
|
-
parsedBorrowIncentivePoolData.maxPoint
|
|
444
|
-
).minus(parsedBorrowIncentivePoolData.distributedPoint);
|
|
445
464
|
const accumulatedPoints = BigNumber.minimum(
|
|
446
465
|
BigNumber(timeDelta).multipliedBy(
|
|
447
|
-
|
|
466
|
+
parsedBorrowIncentivePoolPointData.distributedPointPerPeriod
|
|
448
467
|
),
|
|
449
|
-
|
|
468
|
+
BigNumber(parsedBorrowIncentivePoolPointData.points)
|
|
450
469
|
);
|
|
451
470
|
|
|
452
|
-
const currentPointIndex = BigNumber(
|
|
453
|
-
|
|
471
|
+
const currentPointIndex = BigNumber(
|
|
472
|
+
parsedBorrowIncentivePoolPointData.index
|
|
473
|
+
).plus(
|
|
474
|
+
accumulatedPoints
|
|
475
|
+
.dividedBy(parsedBorrowIncentivePoolPointData.weightedAmount)
|
|
476
|
+
.isFinite()
|
|
454
477
|
? BigNumber(baseIndexRate)
|
|
455
478
|
.multipliedBy(accumulatedPoints)
|
|
456
|
-
.dividedBy(
|
|
479
|
+
.dividedBy(parsedBorrowIncentivePoolPointData.weightedAmount)
|
|
457
480
|
: 0
|
|
458
481
|
);
|
|
459
482
|
const currentTotalDistributedPoint = BigNumber(
|
|
460
|
-
|
|
483
|
+
parsedBorrowIncentivePoolPointData.distributedPoint
|
|
461
484
|
).plus(accumulatedPoints);
|
|
462
485
|
|
|
463
|
-
|
|
464
|
-
const
|
|
465
|
-
const stakedValue = stakedCoin.multipliedBy(borrowIncentiveCoinPrice);
|
|
466
|
-
|
|
467
|
-
return {
|
|
468
|
-
distributedPointPerSec: distributedPointPerSec.toNumber(),
|
|
469
|
-
accumulatedPoints: accumulatedPoints.toNumber(),
|
|
470
|
-
currentPointIndex: currentPointIndex.toNumber(),
|
|
471
|
-
currentTotalDistributedPoint: currentTotalDistributedPoint.toNumber(),
|
|
472
|
-
startDate: new Date(startDate * 1000),
|
|
473
|
-
endDate: new Date(endDate * 1000),
|
|
474
|
-
stakedAmount: stakedAmount.toNumber(),
|
|
475
|
-
stakedCoin: stakedCoin.toNumber(),
|
|
476
|
-
stakedValue: stakedValue.toNumber(),
|
|
477
|
-
};
|
|
478
|
-
};
|
|
479
|
-
|
|
480
|
-
/**
|
|
481
|
-
* Parse origin borrow incentive reward pool data to a more readable format.
|
|
482
|
-
*
|
|
483
|
-
* @param originBorrowIncentiveRewardPoolData - Origin borrow incentive reward pool data
|
|
484
|
-
* @return Parsed borrow incentive reward pool data
|
|
485
|
-
*/
|
|
486
|
-
export const parseOriginBorrowIncentiveRewardPoolData = (
|
|
487
|
-
originBorrowIncentiveRewardPoolData: OriginBorrowIncentiveRewardPoolData
|
|
488
|
-
): ParsedBorrowIncentiveRewardPoolData => {
|
|
489
|
-
return {
|
|
490
|
-
rewardType: normalizeStructTag(
|
|
491
|
-
originBorrowIncentiveRewardPoolData.reward_type.name
|
|
492
|
-
),
|
|
493
|
-
claimedRewards: Number(originBorrowIncentiveRewardPoolData.claimed_rewards),
|
|
494
|
-
exchangeRateNumerator: Number(
|
|
495
|
-
originBorrowIncentiveRewardPoolData.exchange_rate_numerator
|
|
496
|
-
),
|
|
497
|
-
exchangeRateDenominator: Number(
|
|
498
|
-
originBorrowIncentiveRewardPoolData.exchange_rate_denominator
|
|
499
|
-
),
|
|
500
|
-
remainingRewards: Number(
|
|
501
|
-
originBorrowIncentiveRewardPoolData.remaining_reward
|
|
502
|
-
),
|
|
503
|
-
};
|
|
504
|
-
};
|
|
486
|
+
// pure staked amount
|
|
487
|
+
const stakedAmount = BigNumber(pasredBorrowIncentinvePoolData.staked);
|
|
505
488
|
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
calculatedBorrowIncentivePoolData: CalculatedBorrowIncentivePoolData,
|
|
510
|
-
rewardCoinPrice: number,
|
|
511
|
-
rewardCoinDecimal: number
|
|
512
|
-
): CalculatedBorrowIncentiveRewardPoolData => {
|
|
513
|
-
const rateYearFactor = 365 * 24 * 60 * 60;
|
|
489
|
+
const stakedCoin = stakedAmount.shiftedBy(-1 * poolCoinDecimal);
|
|
490
|
+
const stakedValue = stakedCoin.multipliedBy(poolCoinPrice);
|
|
491
|
+
const baseWeight = BigNumber(parsedBorrowIncentivePoolPointData.baseWeight);
|
|
514
492
|
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
.multipliedBy(parsedBorrowIncentiveRewardPoolData.exchangeRateNumerator)
|
|
519
|
-
.dividedBy(parsedBorrowIncentiveRewardPoolData.exchangeRateDenominator);
|
|
520
|
-
const totalRewardAmount = BigNumber(parsedBorrowIncentivePoolData.maxPoint)
|
|
521
|
-
.multipliedBy(parsedBorrowIncentiveRewardPoolData.exchangeRateNumerator)
|
|
522
|
-
.dividedBy(parsedBorrowIncentiveRewardPoolData.exchangeRateDenominator);
|
|
523
|
-
const totalRewardCoin = totalRewardAmount.shiftedBy(-1 * rewardCoinDecimal);
|
|
524
|
-
const totalRewardValue = totalRewardCoin.multipliedBy(rewardCoinPrice);
|
|
525
|
-
const remaindRewardAmount = BigNumber(
|
|
526
|
-
parsedBorrowIncentiveRewardPoolData.remainingRewards
|
|
493
|
+
// staked amount applied with weight
|
|
494
|
+
const weightedStakedAmount = BigNumber(
|
|
495
|
+
parsedBorrowIncentivePoolPointData.weightedAmount
|
|
527
496
|
);
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
const remaindRewardValue = remaindRewardCoin.multipliedBy(rewardCoinPrice);
|
|
532
|
-
const claimedRewardAmount = BigNumber(
|
|
533
|
-
parsedBorrowIncentiveRewardPoolData.claimedRewards
|
|
497
|
+
|
|
498
|
+
const weightedStakedCoin = weightedStakedAmount.shiftedBy(
|
|
499
|
+
-1 * poolCoinDecimal
|
|
534
500
|
);
|
|
535
|
-
const
|
|
536
|
-
|
|
501
|
+
const weightedStakedValue = weightedStakedCoin.multipliedBy(poolCoinPrice);
|
|
502
|
+
|
|
503
|
+
// Calculate the reward rate
|
|
504
|
+
const rateYearFactor = 365 * 24 * 60 * 60;
|
|
505
|
+
const rewardPerSec = BigNumber(distributedPointPerSec).dividedBy(
|
|
506
|
+
parsedBorrowIncentivePoolPointData.period
|
|
537
507
|
);
|
|
538
|
-
const claimedRewardValue = claimedRewardCoin.multipliedBy(rewardCoinPrice);
|
|
539
508
|
|
|
540
509
|
const rewardValueForYear = BigNumber(rewardPerSec)
|
|
541
510
|
.shiftedBy(-1 * rewardCoinDecimal)
|
|
542
511
|
.multipliedBy(rateYearFactor)
|
|
543
512
|
.multipliedBy(rewardCoinPrice);
|
|
513
|
+
|
|
514
|
+
const weightScale = BigNumber('1000000000000');
|
|
544
515
|
const rewardRate = rewardValueForYear
|
|
545
|
-
.dividedBy(
|
|
516
|
+
.dividedBy(weightedStakedValue)
|
|
517
|
+
.multipliedBy(parsedBorrowIncentivePoolPointData.baseWeight)
|
|
518
|
+
.dividedBy(weightScale)
|
|
546
519
|
.isFinite()
|
|
547
520
|
? rewardValueForYear
|
|
548
|
-
.dividedBy(
|
|
521
|
+
.dividedBy(weightedStakedValue)
|
|
522
|
+
.multipliedBy(parsedBorrowIncentivePoolPointData.baseWeight)
|
|
523
|
+
.dividedBy(weightScale)
|
|
549
524
|
.toNumber()
|
|
550
525
|
: Infinity;
|
|
551
526
|
|
|
552
527
|
return {
|
|
528
|
+
distributedPointPerSec: distributedPointPerSec.toNumber(),
|
|
529
|
+
accumulatedPoints: accumulatedPoints.toNumber(),
|
|
530
|
+
currentPointIndex: currentPointIndex.toNumber(),
|
|
531
|
+
currentTotalDistributedPoint: currentTotalDistributedPoint.toNumber(),
|
|
532
|
+
stakedAmount: stakedAmount.toNumber(),
|
|
533
|
+
stakedCoin: stakedCoin.toNumber(),
|
|
534
|
+
stakedValue: stakedValue.toNumber(),
|
|
535
|
+
baseWeight: baseWeight.toNumber(),
|
|
536
|
+
weightedStakedAmount: weightedStakedAmount.toNumber(),
|
|
537
|
+
weightedStakedCoin: weightedStakedCoin.toNumber(),
|
|
538
|
+
weightedStakedValue: weightedStakedValue.toNumber(),
|
|
553
539
|
rewardApr: rewardRate,
|
|
554
|
-
totalRewardAmount: totalRewardAmount.toNumber(),
|
|
555
|
-
totalRewardCoin: totalRewardCoin.toNumber(),
|
|
556
|
-
totalRewardValue: totalRewardValue.toNumber(),
|
|
557
|
-
remaindRewardAmount: remaindRewardAmount.toNumber(),
|
|
558
|
-
remaindRewardCoin: remaindRewardCoin.toNumber(),
|
|
559
|
-
remaindRewardValue: remaindRewardValue.toNumber(),
|
|
560
|
-
claimedRewardAmount: claimedRewardAmount.toNumber(),
|
|
561
|
-
claimedRewardCoin: claimedRewardCoin.toNumber(),
|
|
562
|
-
claimedRewardValue: claimedRewardValue.toNumber(),
|
|
563
540
|
rewardPerSec: rewardPerSec.toNumber(),
|
|
564
541
|
};
|
|
565
542
|
};
|
|
566
543
|
|
|
544
|
+
// /**
|
|
545
|
+
// * Parse origin borrow incentive reward pool data to a more readable format.
|
|
546
|
+
// *
|
|
547
|
+
// * @param originBorrowIncentiveRewardPoolData - Origin borrow incentive reward pool data
|
|
548
|
+
// * @return Parsed borrow incentive reward pool data
|
|
549
|
+
// */
|
|
550
|
+
// export const parseOriginBorrowIncentiveRewardPoolData = (
|
|
551
|
+
// originBorrowIncentiveRewardPoolData: OriginBorrowIncentiveRewardPoolData
|
|
552
|
+
// ): ParsedBorrowIncentiveRewardPoolData => {
|
|
553
|
+
// return {
|
|
554
|
+
// rewardType: normalizeStructTag(
|
|
555
|
+
// originBorrowIncentiveRewardPoolData.reward_type.name
|
|
556
|
+
// ),
|
|
557
|
+
// claimedRewards: Number(originBorrowIncentiveRewardPoolData.claimed_rewards),
|
|
558
|
+
// exchangeRateNumerator: Number(
|
|
559
|
+
// originBorrowIncentiveRewardPoolData.exchange_rate_numerator
|
|
560
|
+
// ),
|
|
561
|
+
// exchangeRateDenominator: Number(
|
|
562
|
+
// originBorrowIncentiveRewardPoolData.exchange_rate_denominator
|
|
563
|
+
// ),
|
|
564
|
+
// remainingRewards: Number(
|
|
565
|
+
// originBorrowIncentiveRewardPoolData.remaining_reward
|
|
566
|
+
// ),
|
|
567
|
+
// };
|
|
568
|
+
// };
|
|
569
|
+
|
|
570
|
+
// export const calculateBorrowIncentiveRewardPoolData = (
|
|
571
|
+
// parsedBorrowIncentivePoolData: ParsedBorrowIncentivePoolData,
|
|
572
|
+
// parsedBorrowIncentiveRewardPoolData: ParsedBorrowIncentiveRewardPoolData,
|
|
573
|
+
// calculatedBorrowIncentivePoolData: CalculatedBorrowIncentivePoolData,
|
|
574
|
+
// rewardCoinPrice: number,
|
|
575
|
+
// rewardCoinDecimal: number
|
|
576
|
+
// ): CalculatedBorrowIncentiveRewardPoolData => {
|
|
577
|
+
// const rateYearFactor = 365 * 24 * 60 * 60;
|
|
578
|
+
|
|
579
|
+
// const rewardPerSec = BigNumber(
|
|
580
|
+
// calculatedBorrowIncentivePoolData.distributedPointPerSec
|
|
581
|
+
// )
|
|
582
|
+
// .multipliedBy(parsedBorrowIncentiveRewardPoolData.exchangeRateNumerator)
|
|
583
|
+
// .dividedBy(parsedBorrowIncentiveRewardPoolData.exchangeRateDenominator);
|
|
584
|
+
// const totalRewardAmount = BigNumber(parsedBorrowIncentivePoolData.maxPoint)
|
|
585
|
+
// .multipliedBy(parsedBorrowIncentiveRewardPoolData.exchangeRateNumerator)
|
|
586
|
+
// .dividedBy(parsedBorrowIncentiveRewardPoolData.exchangeRateDenominator);
|
|
587
|
+
// const totalRewardCoin = totalRewardAmount.shiftedBy(-1 * rewardCoinDecimal);
|
|
588
|
+
// const totalRewardValue = totalRewardCoin.multipliedBy(rewardCoinPrice);
|
|
589
|
+
// const remaindRewardAmount = BigNumber(
|
|
590
|
+
// parsedBorrowIncentiveRewardPoolData.remainingRewards
|
|
591
|
+
// );
|
|
592
|
+
// const remaindRewardCoin = remaindRewardAmount.shiftedBy(
|
|
593
|
+
// -1 * rewardCoinDecimal
|
|
594
|
+
// );
|
|
595
|
+
// const remaindRewardValue = remaindRewardCoin.multipliedBy(rewardCoinPrice);
|
|
596
|
+
// const claimedRewardAmount = BigNumber(
|
|
597
|
+
// parsedBorrowIncentiveRewardPoolData.claimedRewards
|
|
598
|
+
// );
|
|
599
|
+
// const claimedRewardCoin = claimedRewardAmount.shiftedBy(
|
|
600
|
+
// -1 * rewardCoinDecimal
|
|
601
|
+
// );
|
|
602
|
+
// const claimedRewardValue = claimedRewardCoin.multipliedBy(rewardCoinPrice);
|
|
603
|
+
|
|
604
|
+
// const rewardValueForYear = BigNumber(rewardPerSec)
|
|
605
|
+
// .shiftedBy(-1 * rewardCoinDecimal)
|
|
606
|
+
// .multipliedBy(rateYearFactor)
|
|
607
|
+
// .multipliedBy(rewardCoinPrice);
|
|
608
|
+
// const rewardRate = rewardValueForYear
|
|
609
|
+
// .dividedBy(calculatedBorrowIncentivePoolData.stakedValue)
|
|
610
|
+
// .isFinite()
|
|
611
|
+
// ? rewardValueForYear
|
|
612
|
+
// .dividedBy(calculatedBorrowIncentivePoolData.stakedValue)
|
|
613
|
+
// .toNumber()
|
|
614
|
+
// : Infinity;
|
|
615
|
+
|
|
616
|
+
// return {
|
|
617
|
+
// rewardApr: rewardRate,
|
|
618
|
+
// totalRewardAmount: totalRewardAmount.toNumber(),
|
|
619
|
+
// totalRewardCoin: totalRewardCoin.toNumber(),
|
|
620
|
+
// totalRewardValue: totalRewardValue.toNumber(),
|
|
621
|
+
// remaindRewardAmount: remaindRewardAmount.toNumber(),
|
|
622
|
+
// remaindRewardCoin: remaindRewardCoin.toNumber(),
|
|
623
|
+
// remaindRewardValue: remaindRewardValue.toNumber(),
|
|
624
|
+
// claimedRewardAmount: claimedRewardAmount.toNumber(),
|
|
625
|
+
// claimedRewardCoin: claimedRewardCoin.toNumber(),
|
|
626
|
+
// claimedRewardValue: claimedRewardValue.toNumber(),
|
|
627
|
+
// rewardPerSec: rewardPerSec.toNumber(),
|
|
628
|
+
// };
|
|
629
|
+
// };
|
|
630
|
+
|
|
631
|
+
export const parseOriginBorrowIncentiveAccountPoolPointData = (
|
|
632
|
+
originBorrowIncentiveAccountPoolPointData: OriginBorrowIncentiveAccountPoolData
|
|
633
|
+
): ParsedBorrowIncentiveAccountPoolData => {
|
|
634
|
+
return {
|
|
635
|
+
pointType: normalizeStructTag(
|
|
636
|
+
originBorrowIncentiveAccountPoolPointData.point_type.name
|
|
637
|
+
),
|
|
638
|
+
weightedAmount: Number(
|
|
639
|
+
originBorrowIncentiveAccountPoolPointData.weighted_amount
|
|
640
|
+
),
|
|
641
|
+
points: Number(originBorrowIncentiveAccountPoolPointData.points),
|
|
642
|
+
totalPoints: Number(originBorrowIncentiveAccountPoolPointData.total_points),
|
|
643
|
+
index: Number(originBorrowIncentiveAccountPoolPointData.index),
|
|
644
|
+
};
|
|
645
|
+
};
|
|
646
|
+
|
|
567
647
|
/**
|
|
568
648
|
* Parse origin borrow incentive account data to a more readable format.
|
|
569
649
|
*
|
|
@@ -577,10 +657,21 @@ export const parseOriginBorrowIncentiveAccountData = (
|
|
|
577
657
|
poolType: normalizeStructTag(
|
|
578
658
|
originBorrowIncentiveAccountData.pool_type.name
|
|
579
659
|
),
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
660
|
+
debtAmount: Number(originBorrowIncentiveAccountData.debt_amount),
|
|
661
|
+
pointList: originBorrowIncentiveAccountData.points_list.reduce(
|
|
662
|
+
(acc, point) => {
|
|
663
|
+
const parsed = parseOriginBorrowIncentiveAccountPoolPointData(point);
|
|
664
|
+
const name = parseStructTag(
|
|
665
|
+
parsed.pointType
|
|
666
|
+
).name.toLowerCase() as SupportBorrowIncentiveRewardCoins;
|
|
667
|
+
acc[name] = parsed;
|
|
668
|
+
return acc;
|
|
669
|
+
},
|
|
670
|
+
{} as Record<
|
|
671
|
+
SupportBorrowIncentiveRewardCoins,
|
|
672
|
+
ParsedBorrowIncentiveAccountPoolData
|
|
673
|
+
>
|
|
674
|
+
),
|
|
584
675
|
};
|
|
585
676
|
};
|
|
586
677
|
|
package/src/utils/util.ts
CHANGED
|
@@ -3,6 +3,8 @@ import {
|
|
|
3
3
|
SUPPORT_POOLS,
|
|
4
4
|
SUPPORT_COLLATERALS,
|
|
5
5
|
SUPPORT_SPOOLS_REWARDS,
|
|
6
|
+
MAX_LOCK_DURATION,
|
|
7
|
+
SUPPORT_BORROW_INCENTIVE_REWARDS,
|
|
6
8
|
} from '../constants';
|
|
7
9
|
import type { ScallopAddress } from '../models';
|
|
8
10
|
import type {
|
|
@@ -22,6 +24,7 @@ export const isMarketCoin = (
|
|
|
22
24
|
...SUPPORT_POOLS,
|
|
23
25
|
...SUPPORT_COLLATERALS,
|
|
24
26
|
...SUPPORT_SPOOLS_REWARDS,
|
|
27
|
+
...SUPPORT_BORROW_INCENTIVE_REWARDS,
|
|
25
28
|
]),
|
|
26
29
|
].includes(assetCoinName)
|
|
27
30
|
);
|
|
@@ -71,3 +74,28 @@ export const parseDataFromPythPriceFeed = (
|
|
|
71
74
|
throw new Error('Invalid feed id');
|
|
72
75
|
}
|
|
73
76
|
};
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Find the closest unlock round timestamp (12AM) to the given unlock at timestamp in seconds.
|
|
80
|
+
*
|
|
81
|
+
* @param unlockAtInSecondTimestamp - Unlock at in seconds timestamp to find the closest round.
|
|
82
|
+
* @returns Closest round (12AM) in seconds timestamp.
|
|
83
|
+
*/
|
|
84
|
+
export const findClosestUnlockRound = (unlockAtInSecondTimestamp: number) => {
|
|
85
|
+
const unlockDate = new Date(unlockAtInSecondTimestamp * 1000);
|
|
86
|
+
const closestTwelveAM = new Date(unlockAtInSecondTimestamp * 1000);
|
|
87
|
+
|
|
88
|
+
closestTwelveAM.setUTCHours(0, 0, 0, 0); // Set the time to the next 12 AM UTC
|
|
89
|
+
|
|
90
|
+
// If the current time is past 12 AM, set the date to the next day
|
|
91
|
+
if (unlockDate.getUTCHours() >= 0) {
|
|
92
|
+
closestTwelveAM.setUTCDate(closestTwelveAM.getUTCDate() + 1);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const now = new Date().getTime();
|
|
96
|
+
// check if unlock period > 4 years
|
|
97
|
+
if (closestTwelveAM.getTime() - now > MAX_LOCK_DURATION * 1000) {
|
|
98
|
+
closestTwelveAM.setUTCDate(closestTwelveAM.getUTCDate() - 1);
|
|
99
|
+
}
|
|
100
|
+
return Math.floor(closestTwelveAM.getTime() / 1000);
|
|
101
|
+
};
|