@scallop-io/sui-scallop-sdk 0.42.6 → 0.42.8
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/enum.d.ts +3 -1
- package/dist/index.js +183 -109
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +153 -81
- package/dist/index.mjs.map +1 -1
- package/dist/models/scallopUtils.d.ts +1 -0
- package/dist/types/constant/enum.d.ts +8 -0
- package/dist/types/query/core.d.ts +2 -2
- package/dist/types/query/portfolio.d.ts +53 -36
- package/dist/types/query/spool.d.ts +3 -3
- package/dist/utils/query.d.ts +3 -0
- package/package.json +1 -1
- package/src/constants/enum.ts +22 -0
- package/src/models/scallopUtils.ts +36 -13
- package/src/queries/coreQuery.ts +4 -0
- package/src/queries/portfolioQuery.ts +115 -68
- package/src/queries/spoolQuery.ts +2 -2
- package/src/types/constant/enum.ts +13 -0
- package/src/types/query/core.ts +3 -1
- package/src/types/query/portfolio.ts +56 -45
- package/src/types/query/spool.ts +3 -3
- package/src/utils/query.ts +22 -6
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import BigNumber from 'bignumber.js';
|
|
2
2
|
import { SUPPORT_POOLS, SUPPORT_SPOOLS } from '../constants';
|
|
3
|
+
import { minBigNumber } from 'src/utils';
|
|
3
4
|
import type { ScallopQuery } from '../models';
|
|
4
5
|
import type {
|
|
5
6
|
Market,
|
|
@@ -133,7 +134,9 @@ export const getLending = async (
|
|
|
133
134
|
let stakedCoin = BigNumber(0);
|
|
134
135
|
let stakedValue = BigNumber(0);
|
|
135
136
|
let availableUnstakeAmount = BigNumber(0);
|
|
137
|
+
let availableUnstakeCoin = BigNumber(0);
|
|
136
138
|
let availableClaimAmount = BigNumber(0);
|
|
139
|
+
let availableClaimCoin = BigNumber(0);
|
|
137
140
|
|
|
138
141
|
if (spool) {
|
|
139
142
|
for (const stakeAccount of stakeAccounts) {
|
|
@@ -161,6 +164,7 @@ export const getLending = async (
|
|
|
161
164
|
availableUnstakeAmount = availableUnstakeAmount.plus(
|
|
162
165
|
accountStakedMarketCoinAmount
|
|
163
166
|
);
|
|
167
|
+
availableUnstakeCoin = availableUnstakeAmount.shiftedBy(-1 * coinDecimal);
|
|
164
168
|
|
|
165
169
|
const baseIndexRate = 1_000_000_000;
|
|
166
170
|
const increasedPointRate = spool?.currentPointIndex
|
|
@@ -175,6 +179,7 @@ export const getLending = async (
|
|
|
175
179
|
.multipliedBy(spool.exchangeRateNumerator)
|
|
176
180
|
.dividedBy(spool.exchangeRateDenominator)
|
|
177
181
|
);
|
|
182
|
+
availableClaimCoin = availableClaimAmount.shiftedBy(-1 * coinDecimal);
|
|
178
183
|
}
|
|
179
184
|
}
|
|
180
185
|
|
|
@@ -185,6 +190,20 @@ export const getLending = async (
|
|
|
185
190
|
const suppliedCoin = suppliedAmount.shiftedBy(-1 * coinDecimal);
|
|
186
191
|
const suppliedValue = suppliedCoin.multipliedBy(coinPrice ?? 0);
|
|
187
192
|
|
|
193
|
+
const unstakedMarketAmount = BigNumber(marketCoinAmount);
|
|
194
|
+
const unstakedMarketCoin = unstakedMarketAmount.shiftedBy(-1 * coinDecimal);
|
|
195
|
+
|
|
196
|
+
const availableSupplyAmount = BigNumber(coinAmount);
|
|
197
|
+
const availableSupplyCoin = availableSupplyAmount.shiftedBy(-1 * coinDecimal);
|
|
198
|
+
const availableWithdrawAmount = minBigNumber(
|
|
199
|
+
suppliedAmount,
|
|
200
|
+
marketPool?.supplyAmount ?? Infinity
|
|
201
|
+
).plus(stakedAmount);
|
|
202
|
+
const availableWithdrawCoin = minBigNumber(
|
|
203
|
+
suppliedCoin,
|
|
204
|
+
marketPool?.supplyCoin ?? Infinity
|
|
205
|
+
).plus(stakedCoin);
|
|
206
|
+
|
|
188
207
|
const lending: Lending = {
|
|
189
208
|
coinName: poolCoinName,
|
|
190
209
|
symbol: query.utils.parseSymbol(poolCoinName),
|
|
@@ -194,7 +213,7 @@ export const getLending = async (
|
|
|
194
213
|
coinPrice: coinPrice ?? 0,
|
|
195
214
|
supplyApr: marketPool?.supplyApr ?? 0,
|
|
196
215
|
supplyApy: marketPool?.supplyApy ?? 0,
|
|
197
|
-
rewardApr: spool?.
|
|
216
|
+
rewardApr: spool?.rewardApr ?? 0,
|
|
198
217
|
suppliedAmount: suppliedAmount.plus(stakedAmount).toNumber(),
|
|
199
218
|
suppliedCoin: suppliedCoin.plus(stakedCoin).toNumber(),
|
|
200
219
|
suppliedValue: suppliedValue.plus(stakedValue).toNumber(),
|
|
@@ -203,11 +222,21 @@ export const getLending = async (
|
|
|
203
222
|
stakedAmount: stakedAmount.toNumber(),
|
|
204
223
|
stakedCoin: stakedCoin.toNumber(),
|
|
205
224
|
stakedValue: stakedValue.toNumber(),
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
225
|
+
unstakedMarketAmount: unstakedMarketAmount.toNumber(),
|
|
226
|
+
unstakedMarketCoin: unstakedMarketCoin.toNumber(),
|
|
227
|
+
unstakedAmount: suppliedAmount.toNumber(),
|
|
228
|
+
unstakedCoin: suppliedCoin.toNumber(),
|
|
229
|
+
unstakedValue: suppliedValue.toNumber(),
|
|
230
|
+
availableSupplyAmount: availableSupplyAmount.toNumber(),
|
|
231
|
+
availableSupplyCoin: availableSupplyCoin.toNumber(),
|
|
232
|
+
availableWithdrawAmount: availableWithdrawAmount.toNumber(),
|
|
233
|
+
availableWithdrawCoin: availableWithdrawCoin.toNumber(),
|
|
234
|
+
availableStakeAmount: unstakedMarketAmount.toNumber(),
|
|
235
|
+
availableStakeCoin: unstakedMarketCoin.toNumber(),
|
|
209
236
|
availableUnstakeAmount: availableUnstakeAmount.toNumber(),
|
|
237
|
+
availableUnstakeCoin: availableUnstakeCoin.toNumber(),
|
|
210
238
|
availableClaimAmount: availableClaimAmount.toNumber(),
|
|
239
|
+
availableClaimCoin: availableClaimCoin.toNumber(),
|
|
211
240
|
};
|
|
212
241
|
|
|
213
242
|
return lending;
|
|
@@ -275,13 +304,13 @@ export const getObligationAccount = async (
|
|
|
275
304
|
|
|
276
305
|
const collaterals: ObligationAccount['collaterals'] = {};
|
|
277
306
|
const debts: ObligationAccount['debts'] = {};
|
|
278
|
-
let
|
|
279
|
-
let
|
|
307
|
+
let totalDepositedPools = 0;
|
|
308
|
+
let totalDepositedValue = BigNumber(0);
|
|
280
309
|
let totalBorrowCapacityValue = BigNumber(0);
|
|
281
310
|
let totalRequiredCollateralValue = BigNumber(0);
|
|
282
|
-
let
|
|
283
|
-
let
|
|
284
|
-
let
|
|
311
|
+
let totalBorrowedPools = 0;
|
|
312
|
+
let totalBorrowedValue = BigNumber(0);
|
|
313
|
+
let totalBorrowedValueWithWeight = BigNumber(0);
|
|
285
314
|
|
|
286
315
|
for (const collateral of obligationQuery.collaterals) {
|
|
287
316
|
const collateralCoinName =
|
|
@@ -294,13 +323,13 @@ export const getObligationAccount = async (
|
|
|
294
323
|
const coinAmount = coinAmounts?.[collateralCoinName] ?? 0;
|
|
295
324
|
|
|
296
325
|
if (marketCollateral && coinPrice) {
|
|
297
|
-
const
|
|
298
|
-
const
|
|
299
|
-
const
|
|
300
|
-
const borrowCapacityValue =
|
|
326
|
+
const depositedAmount = BigNumber(collateral.amount);
|
|
327
|
+
const depositedCoin = depositedAmount.shiftedBy(-1 * coinDecimal);
|
|
328
|
+
const depositedValue = depositedCoin.multipliedBy(coinPrice);
|
|
329
|
+
const borrowCapacityValue = depositedValue.multipliedBy(
|
|
301
330
|
marketCollateral.collateralFactor
|
|
302
331
|
);
|
|
303
|
-
const requiredCollateralValue =
|
|
332
|
+
const requiredCollateralValue = depositedValue.multipliedBy(
|
|
304
333
|
marketCollateral.liquidationFactor
|
|
305
334
|
);
|
|
306
335
|
const availableDepositAmount = BigNumber(coinAmount);
|
|
@@ -308,23 +337,26 @@ export const getObligationAccount = async (
|
|
|
308
337
|
-1 * coinDecimal
|
|
309
338
|
);
|
|
310
339
|
|
|
311
|
-
|
|
340
|
+
totalDepositedValue = totalDepositedValue.plus(depositedValue);
|
|
312
341
|
totalBorrowCapacityValue =
|
|
313
342
|
totalBorrowCapacityValue.plus(borrowCapacityValue);
|
|
314
343
|
totalRequiredCollateralValue = totalRequiredCollateralValue.plus(
|
|
315
344
|
requiredCollateralValue
|
|
316
345
|
);
|
|
317
346
|
|
|
318
|
-
if (
|
|
319
|
-
|
|
347
|
+
if (depositedAmount.isGreaterThan(0)) {
|
|
348
|
+
totalDepositedPools++;
|
|
320
349
|
}
|
|
321
350
|
|
|
322
351
|
collaterals[collateralCoinName] = {
|
|
323
352
|
coinName: collateralCoinName,
|
|
324
353
|
coinType: collateral.type.name,
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
354
|
+
symbol: query.utils.parseSymbol(collateralCoinName),
|
|
355
|
+
coinDecimal: coinDecimal,
|
|
356
|
+
coinPrice: coinPrice,
|
|
357
|
+
depositedAmount: depositedAmount.toNumber(),
|
|
358
|
+
depositedCoin: depositedCoin.toNumber(),
|
|
359
|
+
depositedValue: depositedValue.toNumber(),
|
|
328
360
|
borrowCapacityValue: borrowCapacityValue.toNumber(),
|
|
329
361
|
requiredCollateralValue: requiredCollateralValue.toNumber(),
|
|
330
362
|
availableDepositAmount: availableDepositAmount.toNumber(),
|
|
@@ -346,32 +378,38 @@ export const getObligationAccount = async (
|
|
|
346
378
|
if (marketPool && coinPrice) {
|
|
347
379
|
const increasedRate =
|
|
348
380
|
marketPool.borrowIndex / Number(debt.borrowIndex) - 1;
|
|
349
|
-
const
|
|
350
|
-
const
|
|
351
|
-
const availableRepayAmount =
|
|
381
|
+
const borrowedAmount = BigNumber(debt.amount);
|
|
382
|
+
const borrowedCoin = borrowedAmount.shiftedBy(-1 * coinDecimal);
|
|
383
|
+
const availableRepayAmount = borrowedAmount.multipliedBy(
|
|
384
|
+
increasedRate + 1
|
|
385
|
+
);
|
|
352
386
|
const availableRepayCoin = availableRepayAmount.shiftedBy(
|
|
353
387
|
-1 * coinDecimal
|
|
354
388
|
);
|
|
355
|
-
const
|
|
356
|
-
const
|
|
389
|
+
const borrowedValue = availableRepayCoin.multipliedBy(coinPrice);
|
|
390
|
+
const borrowedValueWithWeight = borrowedValue.multipliedBy(
|
|
357
391
|
marketPool.borrowWeight
|
|
358
392
|
);
|
|
359
393
|
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
394
|
+
totalBorrowedValue = totalBorrowedValue.plus(borrowedValue);
|
|
395
|
+
totalBorrowedValueWithWeight = totalBorrowedValueWithWeight.plus(
|
|
396
|
+
borrowedValueWithWeight
|
|
397
|
+
);
|
|
363
398
|
|
|
364
|
-
if (
|
|
365
|
-
|
|
399
|
+
if (borrowedAmount.isGreaterThan(0)) {
|
|
400
|
+
totalBorrowedPools++;
|
|
366
401
|
}
|
|
367
402
|
|
|
368
403
|
debts[poolCoinName] = {
|
|
369
404
|
coinName: poolCoinName,
|
|
370
405
|
coinType: debt.type.name,
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
406
|
+
symbol: query.utils.parseSymbol(poolCoinName),
|
|
407
|
+
coinDecimal: coinDecimal,
|
|
408
|
+
coinPrice: coinPrice,
|
|
409
|
+
borrowedAmount: borrowedAmount.toNumber(),
|
|
410
|
+
borrowedCoin: borrowedCoin.toNumber(),
|
|
411
|
+
borrowedValue: borrowedValue.toNumber(),
|
|
412
|
+
borrowedValueWithWeight: borrowedValueWithWeight.toNumber(),
|
|
375
413
|
borrowIndex: Number(debt.borrowIndex),
|
|
376
414
|
availableBorrowAmount: 0,
|
|
377
415
|
availableBorrowCoin: 0,
|
|
@@ -382,55 +420,56 @@ export const getObligationAccount = async (
|
|
|
382
420
|
}
|
|
383
421
|
|
|
384
422
|
let riskLevel =
|
|
385
|
-
totalRequiredCollateralValue.isZero() &&
|
|
423
|
+
totalRequiredCollateralValue.isZero() &&
|
|
424
|
+
totalBorrowedValueWithWeight.isZero()
|
|
386
425
|
? BigNumber(0)
|
|
387
|
-
:
|
|
426
|
+
: totalBorrowedValueWithWeight.dividedBy(totalRequiredCollateralValue);
|
|
388
427
|
riskLevel = riskLevel.isFinite()
|
|
389
428
|
? riskLevel.isLessThan(1)
|
|
390
429
|
? riskLevel
|
|
391
430
|
: BigNumber(1)
|
|
392
431
|
: BigNumber(1);
|
|
393
432
|
|
|
394
|
-
const accountBalanceValue =
|
|
395
|
-
.minus(
|
|
433
|
+
const accountBalanceValue = totalDepositedValue
|
|
434
|
+
.minus(totalBorrowedValue)
|
|
396
435
|
.isGreaterThan(0)
|
|
397
|
-
?
|
|
436
|
+
? totalDepositedValue.minus(totalBorrowedValue)
|
|
398
437
|
: BigNumber(0);
|
|
399
438
|
const availableCollateralValue = totalBorrowCapacityValue
|
|
400
|
-
.minus(
|
|
439
|
+
.minus(totalBorrowedValueWithWeight)
|
|
401
440
|
.isGreaterThan(0)
|
|
402
|
-
? totalBorrowCapacityValue.minus(
|
|
441
|
+
? totalBorrowCapacityValue.minus(totalBorrowedValueWithWeight)
|
|
403
442
|
: BigNumber(0);
|
|
404
|
-
const requiredCollateralValue =
|
|
443
|
+
const requiredCollateralValue = totalBorrowedValueWithWeight.isGreaterThan(0)
|
|
405
444
|
? totalRequiredCollateralValue
|
|
406
445
|
: BigNumber(0);
|
|
407
|
-
const unhealthyCollateralValue =
|
|
446
|
+
const unhealthyCollateralValue = totalBorrowedValueWithWeight
|
|
408
447
|
.minus(requiredCollateralValue)
|
|
409
448
|
.isGreaterThan(0)
|
|
410
|
-
?
|
|
449
|
+
? totalBorrowedValueWithWeight.minus(requiredCollateralValue)
|
|
411
450
|
: BigNumber(0);
|
|
412
451
|
|
|
413
452
|
const obligationAccount: ObligationAccount = {
|
|
414
453
|
obligationId: obligationId,
|
|
415
454
|
// Deposited collateral value (collateral balance)
|
|
416
|
-
|
|
455
|
+
totalDepositedValue: totalDepositedValue.toNumber(),
|
|
417
456
|
// Borrowed debt value (liabilities balance)
|
|
418
|
-
|
|
457
|
+
totalBorrowedValue: totalBorrowedValue.toNumber(),
|
|
419
458
|
// The difference between the user’s actual deposit and loan (remaining balance)
|
|
420
459
|
totalBalanceValue: accountBalanceValue.toNumber(),
|
|
421
460
|
// Effective collateral value (the actual collateral value included in the calculation).
|
|
422
461
|
totalBorrowCapacityValue: totalBorrowCapacityValue.toNumber(),
|
|
423
462
|
// Available collateral value (the remaining collateral value that can be borrowed).
|
|
424
|
-
|
|
463
|
+
totalAvailableCollateralValue: availableCollateralValue.toNumber(),
|
|
425
464
|
// Available debt value (the actual borrowing value included in the calculation).
|
|
426
|
-
|
|
465
|
+
totalBorrowedValueWithWeight: totalBorrowedValueWithWeight.toNumber(),
|
|
427
466
|
// Required collateral value (avoid be liquidated).
|
|
428
|
-
|
|
467
|
+
totalRequiredCollateralValue: requiredCollateralValue.toNumber(),
|
|
429
468
|
// Unliquidated collateral value (pending liquidation).
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
469
|
+
totalUnhealthyCollateralValue: unhealthyCollateralValue.toNumber(),
|
|
470
|
+
totalRiskLevel: riskLevel.toNumber(),
|
|
471
|
+
totalDepositedPools,
|
|
472
|
+
totalBorrowedPools,
|
|
434
473
|
collaterals,
|
|
435
474
|
debts,
|
|
436
475
|
};
|
|
@@ -442,20 +481,23 @@ export const getObligationAccount = async (
|
|
|
442
481
|
market.collaterals[collateralCoinName as SupportCollateralCoins];
|
|
443
482
|
if (marketCollateral) {
|
|
444
483
|
const availableWithdrawAmount =
|
|
445
|
-
obligationAccount.
|
|
446
|
-
? obligationCollateral.
|
|
447
|
-
:
|
|
448
|
-
BigNumber(obligationAccount.
|
|
484
|
+
obligationAccount.totalBorrowedValueWithWeight === 0
|
|
485
|
+
? BigNumber(obligationCollateral.depositedAmount)
|
|
486
|
+
: minBigNumber(
|
|
487
|
+
BigNumber(obligationAccount.totalAvailableCollateralValue)
|
|
449
488
|
.dividedBy(marketCollateral.collateralFactor)
|
|
450
489
|
.dividedBy(marketCollateral.coinPrice)
|
|
451
490
|
// Note: reduced chance of failure when calculations are inaccurate
|
|
452
491
|
.multipliedBy(0.99)
|
|
453
492
|
.toNumber(),
|
|
454
|
-
obligationCollateral.
|
|
493
|
+
obligationCollateral.depositedAmount,
|
|
455
494
|
marketCollateral.depositAmount
|
|
456
495
|
);
|
|
457
|
-
obligationCollateral.availableWithdrawAmount =
|
|
458
|
-
|
|
496
|
+
obligationCollateral.availableWithdrawAmount =
|
|
497
|
+
availableWithdrawAmount.toNumber();
|
|
498
|
+
obligationCollateral.availableWithdrawCoin = availableWithdrawAmount
|
|
499
|
+
.shiftedBy(-1 * obligationCollateral.coinDecimal)
|
|
500
|
+
.toNumber();
|
|
459
501
|
}
|
|
460
502
|
}
|
|
461
503
|
for (const [assetCoinName, obligationDebt] of Object.entries(
|
|
@@ -467,13 +509,12 @@ export const getObligationAccount = async (
|
|
|
467
509
|
obligationDebt.availableRepayAmount
|
|
468
510
|
)
|
|
469
511
|
// Note: reduced chance of failure when calculations are inaccurate
|
|
470
|
-
.multipliedBy(1.01)
|
|
471
|
-
.toNumber();
|
|
512
|
+
.multipliedBy(1.01);
|
|
472
513
|
|
|
473
514
|
const availableBorrowAmount =
|
|
474
|
-
obligationAccount.
|
|
475
|
-
?
|
|
476
|
-
BigNumber(obligationAccount.
|
|
515
|
+
obligationAccount.totalAvailableCollateralValue !== 0
|
|
516
|
+
? minBigNumber(
|
|
517
|
+
BigNumber(obligationAccount.totalAvailableCollateralValue)
|
|
477
518
|
.dividedBy(
|
|
478
519
|
BigNumber(marketPool.coinPrice).multipliedBy(
|
|
479
520
|
marketPool.borrowWeight
|
|
@@ -484,9 +525,15 @@ export const getObligationAccount = async (
|
|
|
484
525
|
.toNumber(),
|
|
485
526
|
marketPool.supplyAmount
|
|
486
527
|
)
|
|
487
|
-
: 0;
|
|
488
|
-
obligationDebt.availableBorrowAmount = availableBorrowAmount;
|
|
489
|
-
obligationDebt.
|
|
528
|
+
: BigNumber(0);
|
|
529
|
+
obligationDebt.availableBorrowAmount = availableBorrowAmount.toNumber();
|
|
530
|
+
obligationDebt.availableBorrowCoin = availableBorrowAmount
|
|
531
|
+
.shiftedBy(-1 * obligationDebt.coinDecimal)
|
|
532
|
+
.toNumber();
|
|
533
|
+
obligationDebt.availableRepayAmount = availableRepayAmount.toNumber();
|
|
534
|
+
obligationDebt.availableRepayCoin = availableRepayAmount
|
|
535
|
+
.shiftedBy(-1 * obligationDebt.coinDecimal)
|
|
536
|
+
.toNumber();
|
|
490
537
|
}
|
|
491
538
|
}
|
|
492
539
|
|
|
@@ -142,8 +142,8 @@ export const getSpool = async (
|
|
|
142
142
|
);
|
|
143
143
|
|
|
144
144
|
spool = {
|
|
145
|
-
|
|
146
|
-
symbol: query.utils.parseSymbol(
|
|
145
|
+
marketCoinName: stakeMarketCoinName,
|
|
146
|
+
symbol: query.utils.parseSymbol(stakeMarketCoinName),
|
|
147
147
|
coinType: query.utils.parseCoinType(stakeCoinName),
|
|
148
148
|
marketCoinType: query.utils.parseMarketCoinType(stakeCoinName),
|
|
149
149
|
rewardCoinType: isMarketCoin(rewardCoin)
|
|
@@ -25,3 +25,16 @@ export type StakeMarketCoins = {
|
|
|
25
25
|
export type RewardCoins = {
|
|
26
26
|
[key in SupportStakeMarketCoins]: SupportRewardCoins;
|
|
27
27
|
};
|
|
28
|
+
|
|
29
|
+
export type AssetCoinIds = {
|
|
30
|
+
[key in SupportAssetCoins]: string;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
type PickFromUnion<T, K extends string> = K extends T ? K : never;
|
|
34
|
+
|
|
35
|
+
export type WormholeCoinIds = {
|
|
36
|
+
[key in PickFromUnion<
|
|
37
|
+
SupportAssetCoins,
|
|
38
|
+
'eth' | 'btc' | 'usdc' | 'usdt' | 'apt' | 'sol'
|
|
39
|
+
>]: string;
|
|
40
|
+
};
|
package/src/types/query/core.ts
CHANGED
|
@@ -114,7 +114,7 @@ export type CollateralStat = { amount: string };
|
|
|
114
114
|
|
|
115
115
|
export type MarketPool = {
|
|
116
116
|
coinName: SupportPoolCoins;
|
|
117
|
-
symbol:
|
|
117
|
+
symbol: string;
|
|
118
118
|
coinType: string;
|
|
119
119
|
marketCoinType: string;
|
|
120
120
|
coinWrappedType: CoinWrappedType;
|
|
@@ -123,6 +123,8 @@ export type MarketPool = {
|
|
|
123
123
|
} & Required<
|
|
124
124
|
Pick<
|
|
125
125
|
ParsedMarketPoolData,
|
|
126
|
+
| 'highKink'
|
|
127
|
+
| 'midKink'
|
|
126
128
|
| 'reserveFactor'
|
|
127
129
|
| 'borrowWeight'
|
|
128
130
|
| 'marketCoinSupplyAmount'
|
|
@@ -32,63 +32,74 @@ export type Lending = Required<
|
|
|
32
32
|
stakedAmount: number;
|
|
33
33
|
stakedCoin: number;
|
|
34
34
|
stakedValue: number;
|
|
35
|
+
unstakedMarketAmount: number;
|
|
36
|
+
unstakedMarketCoin: number;
|
|
37
|
+
unstakedAmount: number;
|
|
38
|
+
unstakedCoin: number;
|
|
39
|
+
unstakedValue: number;
|
|
35
40
|
availableSupplyAmount: number;
|
|
41
|
+
availableSupplyCoin: number;
|
|
36
42
|
availableWithdrawAmount: number;
|
|
43
|
+
availableWithdrawCoin: number;
|
|
37
44
|
availableStakeAmount: number;
|
|
45
|
+
availableStakeCoin: number;
|
|
38
46
|
availableUnstakeAmount: number;
|
|
47
|
+
availableUnstakeCoin: number;
|
|
39
48
|
availableClaimAmount: number;
|
|
49
|
+
availableClaimCoin: number;
|
|
40
50
|
};
|
|
41
51
|
|
|
42
52
|
export type ObligationAccount = {
|
|
43
|
-
obligationId
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
totalDebtValue: number;
|
|
53
|
+
obligationId: string;
|
|
54
|
+
totalDepositedValue: number;
|
|
55
|
+
totalBorrowedValue: number;
|
|
47
56
|
totalBalanceValue: number;
|
|
48
57
|
totalBorrowCapacityValue: number;
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
58
|
+
totalAvailableCollateralValue: number;
|
|
59
|
+
totalBorrowedValueWithWeight: number;
|
|
60
|
+
totalRequiredCollateralValue: number;
|
|
61
|
+
totalUnhealthyCollateralValue: number;
|
|
62
|
+
totalRiskLevel: number;
|
|
63
|
+
totalDepositedPools: number;
|
|
64
|
+
totalBorrowedPools: number;
|
|
56
65
|
collaterals: OptionalKeys<
|
|
57
|
-
Record<
|
|
58
|
-
SupportPoolCoins,
|
|
59
|
-
{
|
|
60
|
-
coinName: string;
|
|
61
|
-
coinType: string;
|
|
62
|
-
collateralAmount: number;
|
|
63
|
-
collateralCoin: number;
|
|
64
|
-
collateralValue: number;
|
|
65
|
-
borrowCapacityValue: number;
|
|
66
|
-
requiredCollateralValue: number;
|
|
67
|
-
availableDepositAmount: number;
|
|
68
|
-
availableDepositCoin: number;
|
|
69
|
-
availableWithdrawAmount: number;
|
|
70
|
-
availableWithdrawCoin: number;
|
|
71
|
-
}
|
|
72
|
-
>
|
|
73
|
-
>;
|
|
74
|
-
debts: OptionalKeys<
|
|
75
|
-
Record<
|
|
76
|
-
SupportCollateralCoins,
|
|
77
|
-
{
|
|
78
|
-
coinName: string;
|
|
79
|
-
coinType: string;
|
|
80
|
-
debtAmount: number;
|
|
81
|
-
debtCoin: number;
|
|
82
|
-
debtValue: number;
|
|
83
|
-
debtValueWithWeight: number;
|
|
84
|
-
borrowIndex: number;
|
|
85
|
-
availableBorrowAmount: number;
|
|
86
|
-
availableBorrowCoin: number;
|
|
87
|
-
availableRepayAmount: number;
|
|
88
|
-
availableRepayCoin: number;
|
|
89
|
-
}
|
|
90
|
-
>
|
|
66
|
+
Record<SupportCollateralCoins, ObligationCollateral>
|
|
91
67
|
>;
|
|
68
|
+
debts: OptionalKeys<Record<SupportPoolCoins, ObligationDebt>>;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
export type ObligationCollateral = {
|
|
72
|
+
coinName: SupportCollateralCoins;
|
|
73
|
+
coinType: string;
|
|
74
|
+
symbol: string;
|
|
75
|
+
coinDecimal: number;
|
|
76
|
+
coinPrice: number;
|
|
77
|
+
depositedAmount: number;
|
|
78
|
+
depositedCoin: number;
|
|
79
|
+
depositedValue: number;
|
|
80
|
+
borrowCapacityValue: number;
|
|
81
|
+
requiredCollateralValue: number;
|
|
82
|
+
availableDepositAmount: number;
|
|
83
|
+
availableDepositCoin: number;
|
|
84
|
+
availableWithdrawAmount: number;
|
|
85
|
+
availableWithdrawCoin: number;
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
export type ObligationDebt = {
|
|
89
|
+
coinName: SupportPoolCoins;
|
|
90
|
+
coinType: string;
|
|
91
|
+
symbol: string;
|
|
92
|
+
coinDecimal: number;
|
|
93
|
+
coinPrice: number;
|
|
94
|
+
borrowedAmount: number;
|
|
95
|
+
borrowedCoin: number;
|
|
96
|
+
borrowedValue: number;
|
|
97
|
+
borrowedValueWithWeight: number;
|
|
98
|
+
borrowIndex: number;
|
|
99
|
+
availableBorrowAmount: number;
|
|
100
|
+
availableBorrowCoin: number;
|
|
101
|
+
availableRepayAmount: number;
|
|
102
|
+
availableRepayCoin: number;
|
|
92
103
|
};
|
|
93
104
|
|
|
94
105
|
export type TotalValueLocked = {
|
package/src/types/query/spool.ts
CHANGED
|
@@ -14,8 +14,8 @@ export type StakeAccounts = Record<SupportStakeMarketCoins, StakeAccount[]>;
|
|
|
14
14
|
export type Spools = OptionalKeys<Record<SupportStakeMarketCoins, Spool>>;
|
|
15
15
|
|
|
16
16
|
export type Spool = {
|
|
17
|
-
|
|
18
|
-
symbol:
|
|
17
|
+
marketCoinName: SupportStakeMarketCoins;
|
|
18
|
+
symbol: string;
|
|
19
19
|
coinType: string;
|
|
20
20
|
marketCoinType: string;
|
|
21
21
|
rewardCoinType: string;
|
|
@@ -82,7 +82,7 @@ export type ParsedRewardPoolData = {
|
|
|
82
82
|
};
|
|
83
83
|
|
|
84
84
|
export type CalculatedRewardPoolData = {
|
|
85
|
-
|
|
85
|
+
rewardApr: number;
|
|
86
86
|
totalRewardAmount: number;
|
|
87
87
|
totalRewardCoin: number;
|
|
88
88
|
totalRewardValue: number;
|
package/src/utils/query.ts
CHANGED
|
@@ -101,12 +101,12 @@ export const calculateMarketPoolData = (
|
|
|
101
101
|
parsedMarketPoolData.debtAmount
|
|
102
102
|
);
|
|
103
103
|
const borrowCoin = borrowAmount.shiftedBy(-1 * coinDecimal);
|
|
104
|
-
const
|
|
104
|
+
const reserveAmount = BigNumber(parsedMarketPoolData.reserveAmount).plus(
|
|
105
105
|
increasedDebtAmount.multipliedBy(parsedMarketPoolData.reserveFactor)
|
|
106
106
|
);
|
|
107
|
-
const reserveCoin =
|
|
107
|
+
const reserveCoin = reserveAmount.shiftedBy(-1 * coinDecimal);
|
|
108
108
|
const supplyAmount = BigNumber(borrowAmount).plus(
|
|
109
|
-
Math.max(parsedMarketPoolData.cashAmount -
|
|
109
|
+
Math.max(parsedMarketPoolData.cashAmount - reserveAmount.toNumber(), 0)
|
|
110
110
|
);
|
|
111
111
|
const supplyCoin = supplyAmount.shiftedBy(-1 * coinDecimal);
|
|
112
112
|
let utilizationRate = BigNumber(borrowAmount).dividedBy(supplyAmount);
|
|
@@ -143,7 +143,7 @@ export const calculateMarketPoolData = (
|
|
|
143
143
|
supplyCoin: supplyCoin.toNumber(),
|
|
144
144
|
borrowAmount: borrowAmount.toNumber(),
|
|
145
145
|
borrowCoin: borrowCoin.toNumber(),
|
|
146
|
-
reserveAmount:
|
|
146
|
+
reserveAmount: reserveAmount.toNumber(),
|
|
147
147
|
reserveCoin: reserveCoin.toNumber(),
|
|
148
148
|
utilizationRate: utilizationRate.toNumber(),
|
|
149
149
|
supplyApr: supplyApr.toNumber(),
|
|
@@ -346,7 +346,7 @@ export const calculateRewardPoolData = (
|
|
|
346
346
|
.shiftedBy(-1 * rewardCoinDecimal)
|
|
347
347
|
.multipliedBy(rateYearFactor)
|
|
348
348
|
.multipliedBy(rewardCoinPrice);
|
|
349
|
-
const
|
|
349
|
+
const rewardRate = rewardValueForYear
|
|
350
350
|
.dividedBy(calculatedStakePoolData.stakedValue)
|
|
351
351
|
.isFinite()
|
|
352
352
|
? rewardValueForYear
|
|
@@ -355,7 +355,7 @@ export const calculateRewardPoolData = (
|
|
|
355
355
|
: Infinity;
|
|
356
356
|
|
|
357
357
|
return {
|
|
358
|
-
|
|
358
|
+
rewardApr: rewardRate,
|
|
359
359
|
totalRewardAmount: totalRewardAmount.toNumber(),
|
|
360
360
|
totalRewardCoin: totalRewardCoin.toNumber(),
|
|
361
361
|
totalRewardValue: totalRewardValue.toNumber(),
|
|
@@ -370,3 +370,19 @@ export const calculateRewardPoolData = (
|
|
|
370
370
|
exchangeRateDenominator: parsedRewardPoolData.exchangeRateDenominator,
|
|
371
371
|
};
|
|
372
372
|
};
|
|
373
|
+
|
|
374
|
+
export const minBigNumber = (...args: BigNumber.Value[]) => {
|
|
375
|
+
return BigNumber(
|
|
376
|
+
args.reduce((min, current) =>
|
|
377
|
+
new BigNumber(current).lt(min) ? current : min
|
|
378
|
+
)
|
|
379
|
+
);
|
|
380
|
+
};
|
|
381
|
+
|
|
382
|
+
export const maxBigNumber = (...args: BigNumber.Value[]) => {
|
|
383
|
+
return BigNumber(
|
|
384
|
+
args.reduce((max, current) =>
|
|
385
|
+
new BigNumber(current).gt(max) ? current : max
|
|
386
|
+
)
|
|
387
|
+
);
|
|
388
|
+
};
|