@scallop-io/sui-scallop-sdk 0.44.17 → 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 +878 -255
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +867 -248
- 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 +227 -131
- 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
|
/**
|
|
@@ -359,12 +361,17 @@ export const calculateSpoolRewardPoolData = (
|
|
|
359
361
|
.shiftedBy(-1 * rewardCoinDecimal)
|
|
360
362
|
.multipliedBy(rateYearFactor)
|
|
361
363
|
.multipliedBy(rewardCoinPrice);
|
|
362
|
-
|
|
364
|
+
|
|
365
|
+
let rewardRate = rewardValueForYear
|
|
363
366
|
.dividedBy(calculatedSpoolData.stakedValue)
|
|
364
367
|
.isFinite()
|
|
365
368
|
? rewardValueForYear.dividedBy(calculatedSpoolData.stakedValue).toNumber()
|
|
366
369
|
: Infinity;
|
|
367
370
|
|
|
371
|
+
if (parsedSpoolData.maxPoint === parsedSpoolData.distributedPoint) {
|
|
372
|
+
rewardRate = Infinity;
|
|
373
|
+
}
|
|
374
|
+
|
|
368
375
|
return {
|
|
369
376
|
rewardApr: rewardRate,
|
|
370
377
|
totalRewardAmount: totalRewardAmount.toNumber(),
|
|
@@ -380,6 +387,28 @@ export const calculateSpoolRewardPoolData = (
|
|
|
380
387
|
};
|
|
381
388
|
};
|
|
382
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
|
+
|
|
383
412
|
/**
|
|
384
413
|
* Parse origin borrow incentive pool data to a more readable format.
|
|
385
414
|
*
|
|
@@ -391,174 +420,230 @@ export const parseOriginBorrowIncentivePoolData = (
|
|
|
391
420
|
): ParsedBorrowIncentivePoolData => {
|
|
392
421
|
return {
|
|
393
422
|
poolType: normalizeStructTag(originBorrowIncentivePoolData.pool_type.name),
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
pointPerPeriod: Number(
|
|
397
|
-
originBorrowIncentivePoolData.distributed_point_per_period
|
|
398
|
-
),
|
|
399
|
-
period: Number(originBorrowIncentivePoolData.point_distribution_time),
|
|
400
|
-
maxStake: Number(originBorrowIncentivePoolData.max_stakes),
|
|
423
|
+
minStakes: Number(originBorrowIncentivePoolData.min_stakes),
|
|
424
|
+
maxStakes: Number(originBorrowIncentivePoolData.max_stakes),
|
|
401
425
|
staked: Number(originBorrowIncentivePoolData.stakes),
|
|
402
|
-
index: Number(originBorrowIncentivePoolData.index),
|
|
403
426
|
createdAt: Number(originBorrowIncentivePoolData.created_at),
|
|
404
|
-
|
|
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
|
+
),
|
|
405
441
|
};
|
|
406
442
|
};
|
|
407
443
|
|
|
408
|
-
export const
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
444
|
+
export const calculateBorrowIncentivePoolPointData = (
|
|
445
|
+
pasredBorrowIncentinvePoolData: ParsedBorrowIncentivePoolData,
|
|
446
|
+
parsedBorrowIncentivePoolPointData: ParsedBorrowIncentivePoolPointData,
|
|
447
|
+
rewardCoinPrice: number,
|
|
448
|
+
rewardCoinDecimal: number,
|
|
449
|
+
poolCoinPrice: number,
|
|
450
|
+
poolCoinDecimal: number
|
|
451
|
+
): CalculatedBorrowIncentivePoolPointData => {
|
|
413
452
|
const baseIndexRate = 1_000_000_000;
|
|
414
453
|
|
|
415
454
|
const distributedPointPerSec = BigNumber(
|
|
416
|
-
|
|
417
|
-
).dividedBy(
|
|
418
|
-
|
|
419
|
-
const pointPerSec = BigNumber(
|
|
420
|
-
parsedBorrowIncentivePoolData.pointPerPeriod
|
|
421
|
-
).dividedBy(parsedBorrowIncentivePoolData.period);
|
|
422
|
-
const remainingPeriod = BigNumber(parsedBorrowIncentivePoolData.maxPoint)
|
|
423
|
-
.minus(parsedBorrowIncentivePoolData.distributedPoint)
|
|
424
|
-
.dividedBy(pointPerSec);
|
|
425
|
-
const startDate = parsedBorrowIncentivePoolData.createdAt;
|
|
426
|
-
const endDate = remainingPeriod
|
|
427
|
-
.plus(parsedBorrowIncentivePoolData.lastUpdate)
|
|
428
|
-
.integerValue()
|
|
429
|
-
.toNumber();
|
|
455
|
+
parsedBorrowIncentivePoolPointData.distributedPointPerPeriod
|
|
456
|
+
).dividedBy(parsedBorrowIncentivePoolPointData.period);
|
|
430
457
|
|
|
431
458
|
const timeDelta = BigNumber(
|
|
432
459
|
Math.floor(new Date().getTime() / 1000) -
|
|
433
|
-
|
|
460
|
+
parsedBorrowIncentivePoolPointData.lastUpdate
|
|
434
461
|
)
|
|
435
|
-
.dividedBy(
|
|
462
|
+
.dividedBy(parsedBorrowIncentivePoolPointData.period)
|
|
436
463
|
.toFixed(0);
|
|
437
|
-
const remainingPoints = BigNumber(
|
|
438
|
-
parsedBorrowIncentivePoolData.maxPoint
|
|
439
|
-
).minus(parsedBorrowIncentivePoolData.distributedPoint);
|
|
440
464
|
const accumulatedPoints = BigNumber.minimum(
|
|
441
465
|
BigNumber(timeDelta).multipliedBy(
|
|
442
|
-
|
|
466
|
+
parsedBorrowIncentivePoolPointData.distributedPointPerPeriod
|
|
443
467
|
),
|
|
444
|
-
|
|
468
|
+
BigNumber(parsedBorrowIncentivePoolPointData.points)
|
|
445
469
|
);
|
|
446
470
|
|
|
447
|
-
const currentPointIndex = BigNumber(
|
|
448
|
-
|
|
471
|
+
const currentPointIndex = BigNumber(
|
|
472
|
+
parsedBorrowIncentivePoolPointData.index
|
|
473
|
+
).plus(
|
|
474
|
+
accumulatedPoints
|
|
475
|
+
.dividedBy(parsedBorrowIncentivePoolPointData.weightedAmount)
|
|
476
|
+
.isFinite()
|
|
449
477
|
? BigNumber(baseIndexRate)
|
|
450
478
|
.multipliedBy(accumulatedPoints)
|
|
451
|
-
.dividedBy(
|
|
479
|
+
.dividedBy(parsedBorrowIncentivePoolPointData.weightedAmount)
|
|
452
480
|
: 0
|
|
453
481
|
);
|
|
454
482
|
const currentTotalDistributedPoint = BigNumber(
|
|
455
|
-
|
|
483
|
+
parsedBorrowIncentivePoolPointData.distributedPoint
|
|
456
484
|
).plus(accumulatedPoints);
|
|
457
485
|
|
|
458
|
-
|
|
459
|
-
const
|
|
460
|
-
const stakedValue = stakedCoin.multipliedBy(borrowIncentiveCoinPrice);
|
|
486
|
+
// pure staked amount
|
|
487
|
+
const stakedAmount = BigNumber(pasredBorrowIncentinvePoolData.staked);
|
|
461
488
|
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
currentPointIndex: currentPointIndex.toNumber(),
|
|
466
|
-
currentTotalDistributedPoint: currentTotalDistributedPoint.toNumber(),
|
|
467
|
-
startDate: new Date(startDate * 1000),
|
|
468
|
-
endDate: new Date(endDate * 1000),
|
|
469
|
-
stakedAmount: stakedAmount.toNumber(),
|
|
470
|
-
stakedCoin: stakedCoin.toNumber(),
|
|
471
|
-
stakedValue: stakedValue.toNumber(),
|
|
472
|
-
};
|
|
473
|
-
};
|
|
474
|
-
|
|
475
|
-
/**
|
|
476
|
-
* Parse origin borrow incentive reward pool data to a more readable format.
|
|
477
|
-
*
|
|
478
|
-
* @param originBorrowIncentiveRewardPoolData - Origin borrow incentive reward pool data
|
|
479
|
-
* @return Parsed borrow incentive reward pool data
|
|
480
|
-
*/
|
|
481
|
-
export const parseOriginBorrowIncentiveRewardPoolData = (
|
|
482
|
-
originBorrowIncentiveRewardPoolData: OriginBorrowIncentiveRewardPoolData
|
|
483
|
-
): ParsedBorrowIncentiveRewardPoolData => {
|
|
484
|
-
return {
|
|
485
|
-
rewardType: normalizeStructTag(
|
|
486
|
-
originBorrowIncentiveRewardPoolData.reward_type.name
|
|
487
|
-
),
|
|
488
|
-
claimedRewards: Number(originBorrowIncentiveRewardPoolData.claimed_rewards),
|
|
489
|
-
exchangeRateNumerator: Number(
|
|
490
|
-
originBorrowIncentiveRewardPoolData.exchange_rate_numerator
|
|
491
|
-
),
|
|
492
|
-
exchangeRateDenominator: Number(
|
|
493
|
-
originBorrowIncentiveRewardPoolData.exchange_rate_denominator
|
|
494
|
-
),
|
|
495
|
-
remainingRewards: Number(
|
|
496
|
-
originBorrowIncentiveRewardPoolData.remaining_reward
|
|
497
|
-
),
|
|
498
|
-
};
|
|
499
|
-
};
|
|
489
|
+
const stakedCoin = stakedAmount.shiftedBy(-1 * poolCoinDecimal);
|
|
490
|
+
const stakedValue = stakedCoin.multipliedBy(poolCoinPrice);
|
|
491
|
+
const baseWeight = BigNumber(parsedBorrowIncentivePoolPointData.baseWeight);
|
|
500
492
|
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
calculatedBorrowIncentivePoolData: CalculatedBorrowIncentivePoolData,
|
|
505
|
-
rewardCoinPrice: number,
|
|
506
|
-
rewardCoinDecimal: number
|
|
507
|
-
): CalculatedBorrowIncentiveRewardPoolData => {
|
|
508
|
-
const rateYearFactor = 365 * 24 * 60 * 60;
|
|
509
|
-
|
|
510
|
-
const rewardPerSec = BigNumber(
|
|
511
|
-
calculatedBorrowIncentivePoolData.distributedPointPerSec
|
|
512
|
-
)
|
|
513
|
-
.multipliedBy(parsedBorrowIncentiveRewardPoolData.exchangeRateNumerator)
|
|
514
|
-
.dividedBy(parsedBorrowIncentiveRewardPoolData.exchangeRateDenominator);
|
|
515
|
-
const totalRewardAmount = BigNumber(parsedBorrowIncentivePoolData.maxPoint)
|
|
516
|
-
.multipliedBy(parsedBorrowIncentiveRewardPoolData.exchangeRateNumerator)
|
|
517
|
-
.dividedBy(parsedBorrowIncentiveRewardPoolData.exchangeRateDenominator);
|
|
518
|
-
const totalRewardCoin = totalRewardAmount.shiftedBy(-1 * rewardCoinDecimal);
|
|
519
|
-
const totalRewardValue = totalRewardCoin.multipliedBy(rewardCoinPrice);
|
|
520
|
-
const remaindRewardAmount = BigNumber(
|
|
521
|
-
parsedBorrowIncentiveRewardPoolData.remainingRewards
|
|
493
|
+
// staked amount applied with weight
|
|
494
|
+
const weightedStakedAmount = BigNumber(
|
|
495
|
+
parsedBorrowIncentivePoolPointData.weightedAmount
|
|
522
496
|
);
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
const remaindRewardValue = remaindRewardCoin.multipliedBy(rewardCoinPrice);
|
|
527
|
-
const claimedRewardAmount = BigNumber(
|
|
528
|
-
parsedBorrowIncentiveRewardPoolData.claimedRewards
|
|
497
|
+
|
|
498
|
+
const weightedStakedCoin = weightedStakedAmount.shiftedBy(
|
|
499
|
+
-1 * poolCoinDecimal
|
|
529
500
|
);
|
|
530
|
-
const
|
|
531
|
-
|
|
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
|
|
532
507
|
);
|
|
533
|
-
const claimedRewardValue = claimedRewardCoin.multipliedBy(rewardCoinPrice);
|
|
534
508
|
|
|
535
509
|
const rewardValueForYear = BigNumber(rewardPerSec)
|
|
536
510
|
.shiftedBy(-1 * rewardCoinDecimal)
|
|
537
511
|
.multipliedBy(rateYearFactor)
|
|
538
512
|
.multipliedBy(rewardCoinPrice);
|
|
513
|
+
|
|
514
|
+
const weightScale = BigNumber('1000000000000');
|
|
539
515
|
const rewardRate = rewardValueForYear
|
|
540
|
-
.dividedBy(
|
|
516
|
+
.dividedBy(weightedStakedValue)
|
|
517
|
+
.multipliedBy(parsedBorrowIncentivePoolPointData.baseWeight)
|
|
518
|
+
.dividedBy(weightScale)
|
|
541
519
|
.isFinite()
|
|
542
520
|
? rewardValueForYear
|
|
543
|
-
.dividedBy(
|
|
521
|
+
.dividedBy(weightedStakedValue)
|
|
522
|
+
.multipliedBy(parsedBorrowIncentivePoolPointData.baseWeight)
|
|
523
|
+
.dividedBy(weightScale)
|
|
544
524
|
.toNumber()
|
|
545
525
|
: Infinity;
|
|
546
526
|
|
|
547
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(),
|
|
548
539
|
rewardApr: rewardRate,
|
|
549
|
-
totalRewardAmount: totalRewardAmount.toNumber(),
|
|
550
|
-
totalRewardCoin: totalRewardCoin.toNumber(),
|
|
551
|
-
totalRewardValue: totalRewardValue.toNumber(),
|
|
552
|
-
remaindRewardAmount: remaindRewardAmount.toNumber(),
|
|
553
|
-
remaindRewardCoin: remaindRewardCoin.toNumber(),
|
|
554
|
-
remaindRewardValue: remaindRewardValue.toNumber(),
|
|
555
|
-
claimedRewardAmount: claimedRewardAmount.toNumber(),
|
|
556
|
-
claimedRewardCoin: claimedRewardCoin.toNumber(),
|
|
557
|
-
claimedRewardValue: claimedRewardValue.toNumber(),
|
|
558
540
|
rewardPerSec: rewardPerSec.toNumber(),
|
|
559
541
|
};
|
|
560
542
|
};
|
|
561
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
|
+
|
|
562
647
|
/**
|
|
563
648
|
* Parse origin borrow incentive account data to a more readable format.
|
|
564
649
|
*
|
|
@@ -572,10 +657,21 @@ export const parseOriginBorrowIncentiveAccountData = (
|
|
|
572
657
|
poolType: normalizeStructTag(
|
|
573
658
|
originBorrowIncentiveAccountData.pool_type.name
|
|
574
659
|
),
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
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
|
+
),
|
|
579
675
|
};
|
|
580
676
|
};
|
|
581
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
|
+
};
|