@scallop-io/sui-scallop-sdk 0.44.2 → 0.44.3
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 +753 -211
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +714 -175
- 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/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 +166 -0
- package/src/queries/coreQuery.ts +57 -15
- package/src/queries/index.ts +1 -0
- package/src/queries/spoolQuery.ts +78 -62
- 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/spool.ts +28 -18
- package/src/utils/builder.ts +15 -0
- package/src/utils/index.ts +1 -1
- package/src/utils/query.ts +277 -70
- package/src/utils/util.ts +36 -2
- package/dist/utils/oracle.d.ts +0 -14
- package/src/utils/oracle.ts +0 -36
package/src/utils/query.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import BigNumber from 'bignumber.js';
|
|
2
|
+
import { normalizeStructTag } from '@mysten/sui.js/utils';
|
|
2
3
|
import type { ScallopUtils } from '../models';
|
|
3
4
|
import type {
|
|
4
5
|
OriginMarketPoolData,
|
|
@@ -7,12 +8,20 @@ import type {
|
|
|
7
8
|
OriginMarketCollateralData,
|
|
8
9
|
ParsedMarketCollateralData,
|
|
9
10
|
CalculatedMarketCollateralData,
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
OriginSpoolData,
|
|
12
|
+
ParsedSpoolData,
|
|
13
|
+
CalculatedSpoolData,
|
|
14
|
+
OriginSpoolRewardPoolData,
|
|
15
|
+
ParsedSpoolRewardPoolData,
|
|
16
|
+
CalculatedSpoolRewardPoolData,
|
|
17
|
+
OriginBorrowIncentivePoolData,
|
|
18
|
+
ParsedBorrowIncentivePoolData,
|
|
19
|
+
CalculatedBorrowIncentivePoolData,
|
|
20
|
+
OriginBorrowIncentiveRewardPoolData,
|
|
21
|
+
ParsedBorrowIncentiveRewardPoolData,
|
|
22
|
+
CalculatedBorrowIncentiveRewardPoolData,
|
|
23
|
+
OriginBorrowIncentiveAccountData,
|
|
24
|
+
ParsedBorrowIncentiveAccountData,
|
|
16
25
|
SupportPoolCoins,
|
|
17
26
|
SupportCollateralCoins,
|
|
18
27
|
} from '../types';
|
|
@@ -207,76 +216,76 @@ export const calculateMarketCollateralData = (
|
|
|
207
216
|
};
|
|
208
217
|
|
|
209
218
|
/**
|
|
210
|
-
* Parse origin
|
|
219
|
+
* Parse origin spool data to a more readable format.
|
|
211
220
|
*
|
|
212
|
-
* @param
|
|
213
|
-
* @return Parsed
|
|
221
|
+
* @param originSpoolData - Origin spool data
|
|
222
|
+
* @return Parsed spool data
|
|
214
223
|
*/
|
|
215
|
-
export const
|
|
216
|
-
|
|
217
|
-
):
|
|
224
|
+
export const parseOriginSpoolData = (
|
|
225
|
+
originSpoolData: OriginSpoolData
|
|
226
|
+
): ParsedSpoolData => {
|
|
218
227
|
return {
|
|
219
|
-
stakeType: '0x' +
|
|
220
|
-
maxPoint: Number(
|
|
221
|
-
distributedPoint: Number(
|
|
222
|
-
pointPerPeriod: Number(
|
|
223
|
-
period: Number(
|
|
224
|
-
maxStake: Number(
|
|
225
|
-
staked: Number(
|
|
226
|
-
index: Number(
|
|
227
|
-
createdAt: Number(
|
|
228
|
-
lastUpdate: Number(
|
|
228
|
+
stakeType: '0x' + originSpoolData.stakeType.fields.name,
|
|
229
|
+
maxPoint: Number(originSpoolData.maxDistributedPoint),
|
|
230
|
+
distributedPoint: Number(originSpoolData.distributedPoint),
|
|
231
|
+
pointPerPeriod: Number(originSpoolData.distributedPointPerPeriod),
|
|
232
|
+
period: Number(originSpoolData.pointDistributionTime),
|
|
233
|
+
maxStake: Number(originSpoolData.maxStake),
|
|
234
|
+
staked: Number(originSpoolData.stakes),
|
|
235
|
+
index: Number(originSpoolData.index),
|
|
236
|
+
createdAt: Number(originSpoolData.createdAt),
|
|
237
|
+
lastUpdate: Number(originSpoolData.lastUpdate),
|
|
229
238
|
};
|
|
230
239
|
};
|
|
231
240
|
|
|
232
|
-
export const
|
|
233
|
-
|
|
241
|
+
export const calculateSpoolData = (
|
|
242
|
+
parsedSpoolData: ParsedSpoolData,
|
|
234
243
|
stakeMarketCoinPrice: number,
|
|
235
244
|
stakeMarketCoinDecimal: number
|
|
236
|
-
):
|
|
245
|
+
): CalculatedSpoolData => {
|
|
237
246
|
const baseIndexRate = 1_000_000_000;
|
|
238
247
|
|
|
239
248
|
const distributedPointPerSec = BigNumber(
|
|
240
|
-
|
|
241
|
-
).dividedBy(
|
|
249
|
+
parsedSpoolData.pointPerPeriod
|
|
250
|
+
).dividedBy(parsedSpoolData.period);
|
|
242
251
|
|
|
243
|
-
const pointPerSec = BigNumber(
|
|
244
|
-
|
|
252
|
+
const pointPerSec = BigNumber(parsedSpoolData.pointPerPeriod).dividedBy(
|
|
253
|
+
parsedSpoolData.period
|
|
245
254
|
);
|
|
246
|
-
const remainingPeriod = BigNumber(
|
|
247
|
-
.minus(
|
|
255
|
+
const remainingPeriod = BigNumber(parsedSpoolData.maxPoint)
|
|
256
|
+
.minus(parsedSpoolData.distributedPoint)
|
|
248
257
|
.dividedBy(pointPerSec);
|
|
249
|
-
const startDate =
|
|
258
|
+
const startDate = parsedSpoolData.createdAt;
|
|
250
259
|
const endDate = remainingPeriod
|
|
251
|
-
.plus(
|
|
260
|
+
.plus(parsedSpoolData.lastUpdate)
|
|
252
261
|
.integerValue()
|
|
253
262
|
.toNumber();
|
|
254
263
|
|
|
255
264
|
const timeDelta = BigNumber(
|
|
256
|
-
Math.floor(new Date().getTime() / 1000) -
|
|
265
|
+
Math.floor(new Date().getTime() / 1000) - parsedSpoolData.lastUpdate
|
|
257
266
|
)
|
|
258
|
-
.dividedBy(
|
|
267
|
+
.dividedBy(parsedSpoolData.period)
|
|
259
268
|
.toFixed(0);
|
|
260
|
-
const remainingPoints = BigNumber(
|
|
261
|
-
|
|
269
|
+
const remainingPoints = BigNumber(parsedSpoolData.maxPoint).minus(
|
|
270
|
+
parsedSpoolData.distributedPoint
|
|
262
271
|
);
|
|
263
272
|
const accumulatedPoints = BigNumber.minimum(
|
|
264
|
-
BigNumber(timeDelta).multipliedBy(
|
|
273
|
+
BigNumber(timeDelta).multipliedBy(parsedSpoolData.pointPerPeriod),
|
|
265
274
|
remainingPoints
|
|
266
275
|
);
|
|
267
276
|
|
|
268
|
-
const currentPointIndex = BigNumber(
|
|
269
|
-
accumulatedPoints.dividedBy(
|
|
277
|
+
const currentPointIndex = BigNumber(parsedSpoolData.index).plus(
|
|
278
|
+
accumulatedPoints.dividedBy(parsedSpoolData.staked).isFinite()
|
|
270
279
|
? BigNumber(baseIndexRate)
|
|
271
280
|
.multipliedBy(accumulatedPoints)
|
|
272
|
-
.dividedBy(
|
|
281
|
+
.dividedBy(parsedSpoolData.staked)
|
|
273
282
|
: 0
|
|
274
283
|
);
|
|
275
284
|
const currentTotalDistributedPoint = BigNumber(
|
|
276
|
-
|
|
285
|
+
parsedSpoolData.distributedPoint
|
|
277
286
|
).plus(accumulatedPoints);
|
|
278
287
|
|
|
279
|
-
const stakedAmount = BigNumber(
|
|
288
|
+
const stakedAmount = BigNumber(parsedSpoolData.staked);
|
|
280
289
|
const stakedCoin = stakedAmount.shiftedBy(-1 * stakeMarketCoinDecimal);
|
|
281
290
|
const stakedValue = stakedCoin.multipliedBy(stakeMarketCoinPrice);
|
|
282
291
|
|
|
@@ -294,49 +303,229 @@ export const calculateStakePoolData = (
|
|
|
294
303
|
};
|
|
295
304
|
|
|
296
305
|
/**
|
|
297
|
-
* Parse origin reward pool data to a more readable format.
|
|
306
|
+
* Parse origin spool reward pool data to a more readable format.
|
|
298
307
|
*
|
|
299
308
|
* @param originRewardPoolData - Origin reward pool data
|
|
300
|
-
* @return Parsed reward pool data
|
|
309
|
+
* @return Parsed spool reward pool data
|
|
301
310
|
*/
|
|
302
|
-
export const
|
|
303
|
-
|
|
304
|
-
):
|
|
311
|
+
export const parseOriginSpoolRewardPoolData = (
|
|
312
|
+
originSpoolRewardPoolData: OriginSpoolRewardPoolData
|
|
313
|
+
): ParsedSpoolRewardPoolData => {
|
|
305
314
|
return {
|
|
306
|
-
claimedRewards: Number(
|
|
307
|
-
exchangeRateNumerator: Number(
|
|
315
|
+
claimedRewards: Number(originSpoolRewardPoolData.claimed_rewards),
|
|
316
|
+
exchangeRateNumerator: Number(
|
|
317
|
+
originSpoolRewardPoolData.exchange_rate_numerator
|
|
318
|
+
),
|
|
308
319
|
exchangeRateDenominator: Number(
|
|
309
|
-
|
|
320
|
+
originSpoolRewardPoolData.exchange_rate_denominator
|
|
310
321
|
),
|
|
311
|
-
rewards: Number(
|
|
312
|
-
spoolId: String(
|
|
322
|
+
rewards: Number(originSpoolRewardPoolData.rewards),
|
|
323
|
+
spoolId: String(originSpoolRewardPoolData.spool_id),
|
|
313
324
|
};
|
|
314
325
|
};
|
|
315
326
|
|
|
316
|
-
export const
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
327
|
+
export const calculateSpoolRewardPoolData = (
|
|
328
|
+
parsedSpoolData: ParsedSpoolData,
|
|
329
|
+
parsedSpoolRewardPoolData: ParsedSpoolRewardPoolData,
|
|
330
|
+
calculatedSpoolData: CalculatedSpoolData,
|
|
320
331
|
rewardCoinPrice: number,
|
|
321
332
|
rewardCoinDecimal: number
|
|
322
|
-
):
|
|
333
|
+
): CalculatedSpoolRewardPoolData => {
|
|
323
334
|
const rateYearFactor = 365 * 24 * 60 * 60;
|
|
324
335
|
|
|
325
|
-
const rewardPerSec = BigNumber(
|
|
326
|
-
.multipliedBy(
|
|
327
|
-
.dividedBy(
|
|
336
|
+
const rewardPerSec = BigNumber(calculatedSpoolData.distributedPointPerSec)
|
|
337
|
+
.multipliedBy(parsedSpoolRewardPoolData.exchangeRateNumerator)
|
|
338
|
+
.dividedBy(parsedSpoolRewardPoolData.exchangeRateDenominator);
|
|
339
|
+
const totalRewardAmount = BigNumber(parsedSpoolData.maxPoint)
|
|
340
|
+
.multipliedBy(parsedSpoolRewardPoolData.exchangeRateNumerator)
|
|
341
|
+
.dividedBy(parsedSpoolRewardPoolData.exchangeRateDenominator);
|
|
342
|
+
const totalRewardCoin = totalRewardAmount.shiftedBy(-1 * rewardCoinDecimal);
|
|
343
|
+
const totalRewardValue = totalRewardCoin.multipliedBy(rewardCoinPrice);
|
|
344
|
+
const remaindRewardAmount = BigNumber(parsedSpoolRewardPoolData.rewards);
|
|
345
|
+
const remaindRewardCoin = remaindRewardAmount.shiftedBy(
|
|
346
|
+
-1 * rewardCoinDecimal
|
|
347
|
+
);
|
|
348
|
+
const remaindRewardValue = remaindRewardCoin.multipliedBy(rewardCoinPrice);
|
|
349
|
+
const claimedRewardAmount = BigNumber(
|
|
350
|
+
parsedSpoolRewardPoolData.claimedRewards
|
|
351
|
+
);
|
|
352
|
+
const claimedRewardCoin = claimedRewardAmount.shiftedBy(
|
|
353
|
+
-1 * rewardCoinDecimal
|
|
354
|
+
);
|
|
355
|
+
const claimedRewardValue = claimedRewardCoin.multipliedBy(rewardCoinPrice);
|
|
356
|
+
|
|
357
|
+
const rewardValueForYear = BigNumber(rewardPerSec)
|
|
358
|
+
.shiftedBy(-1 * rewardCoinDecimal)
|
|
359
|
+
.multipliedBy(rateYearFactor)
|
|
360
|
+
.multipliedBy(rewardCoinPrice);
|
|
361
|
+
const rewardRate = rewardValueForYear
|
|
362
|
+
.dividedBy(calculatedSpoolData.stakedValue)
|
|
363
|
+
.isFinite()
|
|
364
|
+
? rewardValueForYear.dividedBy(calculatedSpoolData.stakedValue).toNumber()
|
|
365
|
+
: Infinity;
|
|
366
|
+
|
|
367
|
+
return {
|
|
368
|
+
rewardApr: rewardRate,
|
|
369
|
+
totalRewardAmount: totalRewardAmount.toNumber(),
|
|
370
|
+
totalRewardCoin: totalRewardCoin.toNumber(),
|
|
371
|
+
totalRewardValue: totalRewardValue.toNumber(),
|
|
372
|
+
remaindRewardAmount: remaindRewardAmount.toNumber(),
|
|
373
|
+
remaindRewardCoin: remaindRewardCoin.toNumber(),
|
|
374
|
+
remaindRewardValue: remaindRewardValue.toNumber(),
|
|
375
|
+
claimedRewardAmount: claimedRewardAmount.toNumber(),
|
|
376
|
+
claimedRewardCoin: claimedRewardCoin.toNumber(),
|
|
377
|
+
claimedRewardValue: claimedRewardValue.toNumber(),
|
|
378
|
+
rewardPerSec: rewardPerSec.toNumber(),
|
|
379
|
+
};
|
|
380
|
+
};
|
|
381
|
+
|
|
382
|
+
/**
|
|
383
|
+
* Parse origin borrow incentive pool data to a more readable format.
|
|
384
|
+
*
|
|
385
|
+
* @param originBorrowIncentivePoolData - Origin borrow incentive pool data
|
|
386
|
+
* @return Parsed borrow incentive pool data
|
|
387
|
+
*/
|
|
388
|
+
export const parseOriginBorrowIncentivePoolData = (
|
|
389
|
+
originBorrowIncentivePoolData: OriginBorrowIncentivePoolData
|
|
390
|
+
): ParsedBorrowIncentivePoolData => {
|
|
391
|
+
return {
|
|
392
|
+
poolType: normalizeStructTag(originBorrowIncentivePoolData.pool_type.name),
|
|
393
|
+
maxPoint: Number(originBorrowIncentivePoolData.max_distributed_point),
|
|
394
|
+
distributedPoint: Number(originBorrowIncentivePoolData.distributed_point),
|
|
395
|
+
pointPerPeriod: Number(
|
|
396
|
+
originBorrowIncentivePoolData.distributed_point_per_period
|
|
397
|
+
),
|
|
398
|
+
period: Number(originBorrowIncentivePoolData.point_distribution_time),
|
|
399
|
+
maxStake: Number(originBorrowIncentivePoolData.max_stakes),
|
|
400
|
+
staked: Number(originBorrowIncentivePoolData.stakes),
|
|
401
|
+
index: Number(originBorrowIncentivePoolData.index),
|
|
402
|
+
createdAt: Number(originBorrowIncentivePoolData.created_at),
|
|
403
|
+
lastUpdate: Number(originBorrowIncentivePoolData.last_update),
|
|
404
|
+
};
|
|
405
|
+
};
|
|
406
|
+
|
|
407
|
+
export const calculateBorrowIncentivePoolData = (
|
|
408
|
+
parsedBorrowIncentivePoolData: ParsedBorrowIncentivePoolData,
|
|
409
|
+
borrowIncentiveCoinPrice: number,
|
|
410
|
+
borrowIncentiveCoinDecimal: number
|
|
411
|
+
): CalculatedBorrowIncentivePoolData => {
|
|
412
|
+
const baseIndexRate = 1_000_000_000;
|
|
413
|
+
|
|
414
|
+
const distributedPointPerSec = BigNumber(
|
|
415
|
+
parsedBorrowIncentivePoolData.pointPerPeriod
|
|
416
|
+
).dividedBy(parsedBorrowIncentivePoolData.period);
|
|
417
|
+
|
|
418
|
+
const pointPerSec = BigNumber(
|
|
419
|
+
parsedBorrowIncentivePoolData.pointPerPeriod
|
|
420
|
+
).dividedBy(parsedBorrowIncentivePoolData.period);
|
|
421
|
+
const remainingPeriod = BigNumber(parsedBorrowIncentivePoolData.maxPoint)
|
|
422
|
+
.minus(parsedBorrowIncentivePoolData.distributedPoint)
|
|
423
|
+
.dividedBy(pointPerSec);
|
|
424
|
+
const startDate = parsedBorrowIncentivePoolData.createdAt;
|
|
425
|
+
const endDate = remainingPeriod
|
|
426
|
+
.plus(parsedBorrowIncentivePoolData.lastUpdate)
|
|
427
|
+
.integerValue()
|
|
428
|
+
.toNumber();
|
|
429
|
+
|
|
430
|
+
const timeDelta = BigNumber(
|
|
431
|
+
Math.floor(new Date().getTime() / 1000) -
|
|
432
|
+
parsedBorrowIncentivePoolData.lastUpdate
|
|
433
|
+
)
|
|
434
|
+
.dividedBy(parsedBorrowIncentivePoolData.period)
|
|
435
|
+
.toFixed(0);
|
|
436
|
+
const remainingPoints = BigNumber(
|
|
437
|
+
parsedBorrowIncentivePoolData.maxPoint
|
|
438
|
+
).minus(parsedBorrowIncentivePoolData.distributedPoint);
|
|
439
|
+
const accumulatedPoints = BigNumber.minimum(
|
|
440
|
+
BigNumber(timeDelta).multipliedBy(
|
|
441
|
+
parsedBorrowIncentivePoolData.pointPerPeriod
|
|
442
|
+
),
|
|
443
|
+
remainingPoints
|
|
444
|
+
);
|
|
445
|
+
|
|
446
|
+
const currentPointIndex = BigNumber(parsedBorrowIncentivePoolData.index).plus(
|
|
447
|
+
accumulatedPoints.dividedBy(parsedBorrowIncentivePoolData.staked).isFinite()
|
|
448
|
+
? BigNumber(baseIndexRate)
|
|
449
|
+
.multipliedBy(accumulatedPoints)
|
|
450
|
+
.dividedBy(parsedBorrowIncentivePoolData.staked)
|
|
451
|
+
: 0
|
|
452
|
+
);
|
|
453
|
+
const currentTotalDistributedPoint = BigNumber(
|
|
454
|
+
parsedBorrowIncentivePoolData.distributedPoint
|
|
455
|
+
).plus(accumulatedPoints);
|
|
456
|
+
|
|
457
|
+
const stakedAmount = BigNumber(parsedBorrowIncentivePoolData.staked);
|
|
458
|
+
const stakedCoin = stakedAmount.shiftedBy(-1 * borrowIncentiveCoinDecimal);
|
|
459
|
+
const stakedValue = stakedCoin.multipliedBy(borrowIncentiveCoinPrice);
|
|
460
|
+
|
|
461
|
+
return {
|
|
462
|
+
distributedPointPerSec: distributedPointPerSec.toNumber(),
|
|
463
|
+
accumulatedPoints: accumulatedPoints.toNumber(),
|
|
464
|
+
currentPointIndex: currentPointIndex.toNumber(),
|
|
465
|
+
currentTotalDistributedPoint: currentTotalDistributedPoint.toNumber(),
|
|
466
|
+
startDate: new Date(startDate * 1000),
|
|
467
|
+
endDate: new Date(endDate * 1000),
|
|
468
|
+
stakedAmount: stakedAmount.toNumber(),
|
|
469
|
+
stakedCoin: stakedCoin.toNumber(),
|
|
470
|
+
stakedValue: stakedValue.toNumber(),
|
|
471
|
+
};
|
|
472
|
+
};
|
|
473
|
+
|
|
474
|
+
/**
|
|
475
|
+
* Parse origin borrow incentive reward pool data to a more readable format.
|
|
476
|
+
*
|
|
477
|
+
* @param originBorrowIncentiveRewardPoolData - Origin borrow incentive reward pool data
|
|
478
|
+
* @return Parsed borrow incentive reward pool data
|
|
479
|
+
*/
|
|
480
|
+
export const parseOriginBorrowIncentiveRewardPoolData = (
|
|
481
|
+
originBorrowIncentiveRewardPoolData: OriginBorrowIncentiveRewardPoolData
|
|
482
|
+
): ParsedBorrowIncentiveRewardPoolData => {
|
|
483
|
+
return {
|
|
484
|
+
rewardType: normalizeStructTag(
|
|
485
|
+
originBorrowIncentiveRewardPoolData.reward_type.name
|
|
486
|
+
),
|
|
487
|
+
claimedRewards: Number(originBorrowIncentiveRewardPoolData.claimed_rewards),
|
|
488
|
+
exchangeRateNumerator: Number(
|
|
489
|
+
originBorrowIncentiveRewardPoolData.exchange_rate_numerator
|
|
490
|
+
),
|
|
491
|
+
exchangeRateDenominator: Number(
|
|
492
|
+
originBorrowIncentiveRewardPoolData.exchange_rate_denominator
|
|
493
|
+
),
|
|
494
|
+
remainingRewards: Number(
|
|
495
|
+
originBorrowIncentiveRewardPoolData.remaining_reward
|
|
496
|
+
),
|
|
497
|
+
};
|
|
498
|
+
};
|
|
328
499
|
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
500
|
+
export const calculateBorrowIncentiveRewardPoolData = (
|
|
501
|
+
parsedBorrowIncentivePoolData: ParsedBorrowIncentivePoolData,
|
|
502
|
+
parsedBorrowIncentiveRewardPoolData: ParsedBorrowIncentiveRewardPoolData,
|
|
503
|
+
calculatedBorrowIncentivePoolData: CalculatedBorrowIncentivePoolData,
|
|
504
|
+
rewardCoinPrice: number,
|
|
505
|
+
rewardCoinDecimal: number
|
|
506
|
+
): CalculatedBorrowIncentiveRewardPoolData => {
|
|
507
|
+
const rateYearFactor = 365 * 24 * 60 * 60;
|
|
508
|
+
|
|
509
|
+
const rewardPerSec = BigNumber(
|
|
510
|
+
calculatedBorrowIncentivePoolData.distributedPointPerSec
|
|
511
|
+
)
|
|
512
|
+
.multipliedBy(parsedBorrowIncentiveRewardPoolData.exchangeRateNumerator)
|
|
513
|
+
.dividedBy(parsedBorrowIncentiveRewardPoolData.exchangeRateDenominator);
|
|
514
|
+
const totalRewardAmount = BigNumber(parsedBorrowIncentivePoolData.maxPoint)
|
|
515
|
+
.multipliedBy(parsedBorrowIncentiveRewardPoolData.exchangeRateNumerator)
|
|
516
|
+
.dividedBy(parsedBorrowIncentiveRewardPoolData.exchangeRateDenominator);
|
|
332
517
|
const totalRewardCoin = totalRewardAmount.shiftedBy(-1 * rewardCoinDecimal);
|
|
333
518
|
const totalRewardValue = totalRewardCoin.multipliedBy(rewardCoinPrice);
|
|
334
|
-
const remaindRewardAmount = BigNumber(
|
|
519
|
+
const remaindRewardAmount = BigNumber(
|
|
520
|
+
parsedBorrowIncentiveRewardPoolData.remainingRewards
|
|
521
|
+
);
|
|
335
522
|
const remaindRewardCoin = remaindRewardAmount.shiftedBy(
|
|
336
523
|
-1 * rewardCoinDecimal
|
|
337
524
|
);
|
|
338
525
|
const remaindRewardValue = remaindRewardCoin.multipliedBy(rewardCoinPrice);
|
|
339
|
-
const claimedRewardAmount = BigNumber(
|
|
526
|
+
const claimedRewardAmount = BigNumber(
|
|
527
|
+
parsedBorrowIncentiveRewardPoolData.claimedRewards
|
|
528
|
+
);
|
|
340
529
|
const claimedRewardCoin = claimedRewardAmount.shiftedBy(
|
|
341
530
|
-1 * rewardCoinDecimal
|
|
342
531
|
);
|
|
@@ -347,10 +536,10 @@ export const calculateRewardPoolData = (
|
|
|
347
536
|
.multipliedBy(rateYearFactor)
|
|
348
537
|
.multipliedBy(rewardCoinPrice);
|
|
349
538
|
const rewardRate = rewardValueForYear
|
|
350
|
-
.dividedBy(
|
|
539
|
+
.dividedBy(calculatedBorrowIncentivePoolData.stakedValue)
|
|
351
540
|
.isFinite()
|
|
352
541
|
? rewardValueForYear
|
|
353
|
-
.dividedBy(
|
|
542
|
+
.dividedBy(calculatedBorrowIncentivePoolData.stakedValue)
|
|
354
543
|
.toNumber()
|
|
355
544
|
: Infinity;
|
|
356
545
|
|
|
@@ -366,8 +555,26 @@ export const calculateRewardPoolData = (
|
|
|
366
555
|
claimedRewardCoin: claimedRewardCoin.toNumber(),
|
|
367
556
|
claimedRewardValue: claimedRewardValue.toNumber(),
|
|
368
557
|
rewardPerSec: rewardPerSec.toNumber(),
|
|
369
|
-
|
|
370
|
-
|
|
558
|
+
};
|
|
559
|
+
};
|
|
560
|
+
|
|
561
|
+
/**
|
|
562
|
+
* Parse origin borrow incentive account data to a more readable format.
|
|
563
|
+
*
|
|
564
|
+
* @param originBorrowIncentiveAccountData - Origin borrow incentive account data
|
|
565
|
+
* @return Parsed borrow incentive account data
|
|
566
|
+
*/
|
|
567
|
+
export const parseOriginBorrowIncentiveAccountData = (
|
|
568
|
+
originBorrowIncentiveAccountData: OriginBorrowIncentiveAccountData
|
|
569
|
+
): ParsedBorrowIncentiveAccountData => {
|
|
570
|
+
return {
|
|
571
|
+
poolType: normalizeStructTag(
|
|
572
|
+
originBorrowIncentiveAccountData.pool_type.name
|
|
573
|
+
),
|
|
574
|
+
amount: Number(originBorrowIncentiveAccountData.amount),
|
|
575
|
+
index: Number(originBorrowIncentiveAccountData.index),
|
|
576
|
+
points: Number(originBorrowIncentiveAccountData.points),
|
|
577
|
+
totalPoints: Number(originBorrowIncentiveAccountData.total_points),
|
|
371
578
|
};
|
|
372
579
|
};
|
|
373
580
|
|
package/src/utils/util.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
import type { PriceFeed } from '@pythnetwork/pyth-sui-js';
|
|
1
2
|
import {
|
|
2
3
|
SUPPORT_POOLS,
|
|
3
4
|
SUPPORT_COLLATERALS,
|
|
4
|
-
|
|
5
|
+
SUPPORT_SPOOLS_REWARDS,
|
|
5
6
|
} from '../constants';
|
|
7
|
+
import type { ScallopAddress } from '../models';
|
|
6
8
|
import type {
|
|
7
9
|
SupportAssetCoins,
|
|
8
10
|
SupportCoins,
|
|
@@ -19,7 +21,7 @@ export const isMarketCoin = (
|
|
|
19
21
|
...new Set([
|
|
20
22
|
...SUPPORT_POOLS,
|
|
21
23
|
...SUPPORT_COLLATERALS,
|
|
22
|
-
...
|
|
24
|
+
...SUPPORT_SPOOLS_REWARDS,
|
|
23
25
|
]),
|
|
24
26
|
].includes(assetCoinName)
|
|
25
27
|
);
|
|
@@ -37,3 +39,35 @@ export const parseAssetSymbol = (coinName: SupportAssetCoins): string => {
|
|
|
37
39
|
return coinName.toUpperCase();
|
|
38
40
|
}
|
|
39
41
|
};
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Parse price from pyth price feed.
|
|
45
|
+
*
|
|
46
|
+
* @param feed - Price feed object from pyth.
|
|
47
|
+
* @param address - Scallop address instance.
|
|
48
|
+
* @return Price Data inclue coin name, price, and publish time.
|
|
49
|
+
*/
|
|
50
|
+
export const parseDataFromPythPriceFeed = (
|
|
51
|
+
feed: PriceFeed,
|
|
52
|
+
address: ScallopAddress
|
|
53
|
+
) => {
|
|
54
|
+
const assetCoinNames = [
|
|
55
|
+
...new Set([...SUPPORT_POOLS, ...SUPPORT_COLLATERALS]),
|
|
56
|
+
] as SupportAssetCoins[];
|
|
57
|
+
const assetCoinName = assetCoinNames.find((assetCoinName) => {
|
|
58
|
+
return (
|
|
59
|
+
address.get(`core.coins.${assetCoinName}.oracle.pyth.feed`) === feed.id
|
|
60
|
+
);
|
|
61
|
+
});
|
|
62
|
+
if (assetCoinName) {
|
|
63
|
+
const price = feed.price.price * 10 ** feed.price.expo;
|
|
64
|
+
|
|
65
|
+
return {
|
|
66
|
+
coinName: assetCoinName,
|
|
67
|
+
price,
|
|
68
|
+
publishTime: Number(feed.price.publishTime) * 10 ** 3,
|
|
69
|
+
};
|
|
70
|
+
} else {
|
|
71
|
+
throw new Error('Invalid feed id');
|
|
72
|
+
}
|
|
73
|
+
};
|
package/dist/utils/oracle.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { ScallopAddress } from '../models';
|
|
2
|
-
import type { SupportAssetCoins } from '../types';
|
|
3
|
-
/**
|
|
4
|
-
* Parse price from pyth price feed.
|
|
5
|
-
*
|
|
6
|
-
* @param feed - Price feed object from pyth.
|
|
7
|
-
* @param address - Scallop address instance.
|
|
8
|
-
* @return Price Data inclue coin name, price, and publish time.
|
|
9
|
-
*/
|
|
10
|
-
export declare const parseDataFromPythPriceFeed: (feed: PriceFeed, address: ScallopAddress) => {
|
|
11
|
-
coinName: SupportAssetCoins;
|
|
12
|
-
price: number;
|
|
13
|
-
publishTime: number;
|
|
14
|
-
};
|
package/src/utils/oracle.ts
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { SUPPORT_POOLS, SUPPORT_COLLATERALS } from '../constants';
|
|
2
|
-
import type { PriceFeed } from '@pythnetwork/pyth-sui-js';
|
|
3
|
-
import type { ScallopAddress } from '../models';
|
|
4
|
-
import type { SupportAssetCoins } from '../types';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Parse price from pyth price feed.
|
|
8
|
-
*
|
|
9
|
-
* @param feed - Price feed object from pyth.
|
|
10
|
-
* @param address - Scallop address instance.
|
|
11
|
-
* @return Price Data inclue coin name, price, and publish time.
|
|
12
|
-
*/
|
|
13
|
-
export const parseDataFromPythPriceFeed = (
|
|
14
|
-
feed: PriceFeed,
|
|
15
|
-
address: ScallopAddress
|
|
16
|
-
) => {
|
|
17
|
-
const assetCoinNames = [
|
|
18
|
-
...new Set([...SUPPORT_POOLS, ...SUPPORT_COLLATERALS]),
|
|
19
|
-
] as SupportAssetCoins[];
|
|
20
|
-
const assetCoinName = assetCoinNames.find((assetCoinName) => {
|
|
21
|
-
return (
|
|
22
|
-
address.get(`core.coins.${assetCoinName}.oracle.pyth.feed`) === feed.id
|
|
23
|
-
);
|
|
24
|
-
});
|
|
25
|
-
if (assetCoinName) {
|
|
26
|
-
const price = feed.price.price * 10 ** feed.price.expo;
|
|
27
|
-
|
|
28
|
-
return {
|
|
29
|
-
coinName: assetCoinName,
|
|
30
|
-
price,
|
|
31
|
-
publishTime: Number(feed.price.publishTime) * 10 ** 3,
|
|
32
|
-
};
|
|
33
|
-
} else {
|
|
34
|
-
throw new Error('Invalid feed id');
|
|
35
|
-
}
|
|
36
|
-
};
|