@scallop-io/sui-scallop-sdk 1.3.5-rc.1 → 1.4.0
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/common.d.ts +1 -1
- package/dist/constants/enum.d.ts +1 -1
- package/dist/constants/tokenBucket.d.ts +1 -1
- package/dist/index.js +299 -340
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +298 -339
- package/dist/index.mjs.map +1 -1
- package/dist/models/scallopClient.d.ts +4 -4
- package/dist/models/scallopQuery.d.ts +35 -57
- package/dist/models/scallopUtils.d.ts +10 -10
- package/dist/queries/borrowIncentiveQuery.d.ts +2 -2
- package/dist/queries/priceQuery.d.ts +2 -36
- package/dist/types/builder/borrowIncentive.d.ts +6 -6
- package/dist/types/constant/common.d.ts +1 -1
- package/dist/types/utils.d.ts +6 -2
- package/package.json +1 -1
- package/src/builders/borrowIncentiveBuilder.ts +13 -2
- package/src/constants/common.ts +2 -4
- package/src/constants/enum.ts +16 -11
- package/src/constants/tokenBucket.ts +1 -1
- package/src/models/scallopClient.ts +10 -27
- package/src/models/scallopQuery.ts +38 -44
- package/src/models/scallopUtils.ts +18 -23
- package/src/queries/borrowIncentiveQuery.ts +12 -29
- package/src/queries/coreQuery.ts +191 -191
- package/src/queries/portfolioQuery.ts +78 -80
- package/src/queries/priceQuery.ts +2 -36
- package/src/queries/sCoinQuery.ts +3 -3
- package/src/queries/spoolQuery.ts +6 -4
- package/src/types/builder/borrowIncentive.ts +15 -10
- package/src/types/constant/common.ts +2 -1
- package/src/types/utils.ts +10 -2
- package/src/utils/indexer.ts +9 -3
- package/src/utils/query.ts +87 -0
- package/src/utils/tokenBucket.ts +2 -2
package/src/queries/coreQuery.ts
CHANGED
|
@@ -247,7 +247,7 @@ export const getMarketPools = async (
|
|
|
247
247
|
const marketObjectResponse = await query.cache.queryGetObject(marketId, {
|
|
248
248
|
showContent: true,
|
|
249
249
|
});
|
|
250
|
-
coinPrices =
|
|
250
|
+
coinPrices = (await query.utils.getCoinPrices(poolCoinNames)) ?? {};
|
|
251
251
|
|
|
252
252
|
const marketPools: MarketPools = {};
|
|
253
253
|
|
|
@@ -305,221 +305,217 @@ export const getMarketPool = async (
|
|
|
305
305
|
marketObject?: SuiObjectData | null,
|
|
306
306
|
coinPrice?: number
|
|
307
307
|
): Promise<MarketPool | undefined> => {
|
|
308
|
-
|
|
309
|
-
coinPrice
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
if (indexer) {
|
|
313
|
-
const marketPoolIndexer = await query.indexer.getMarketPool(poolCoinName);
|
|
314
|
-
if (!marketPoolIndexer) {
|
|
315
|
-
return undefined;
|
|
316
|
-
}
|
|
317
|
-
marketPoolIndexer.coinPrice = coinPrice ?? marketPoolIndexer.coinPrice;
|
|
318
|
-
marketPoolIndexer.coinWrappedType = query.utils.getCoinWrappedType(
|
|
319
|
-
marketPoolIndexer.coinName
|
|
320
|
-
);
|
|
308
|
+
coinPrice =
|
|
309
|
+
coinPrice ||
|
|
310
|
+
(await query.utils.getCoinPrices([poolCoinName]))?.[poolCoinName];
|
|
321
311
|
|
|
322
|
-
|
|
312
|
+
if (indexer) {
|
|
313
|
+
const marketPoolIndexer = await query.indexer.getMarketPool(poolCoinName);
|
|
314
|
+
if (!marketPoolIndexer) {
|
|
315
|
+
return undefined;
|
|
323
316
|
}
|
|
317
|
+
marketPoolIndexer.coinPrice = coinPrice ?? marketPoolIndexer.coinPrice;
|
|
318
|
+
marketPoolIndexer.coinWrappedType = query.utils.getCoinWrappedType(
|
|
319
|
+
marketPoolIndexer.coinName
|
|
320
|
+
);
|
|
324
321
|
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
marketObject ||
|
|
328
|
-
(
|
|
329
|
-
await query.cache.queryGetObject(marketId, {
|
|
330
|
-
showContent: true,
|
|
331
|
-
})
|
|
332
|
-
)?.data;
|
|
322
|
+
return marketPoolIndexer;
|
|
323
|
+
}
|
|
333
324
|
|
|
334
|
-
|
|
335
|
-
|
|
325
|
+
const marketId = query.address.get('core.market');
|
|
326
|
+
marketObject =
|
|
327
|
+
marketObject ||
|
|
328
|
+
(
|
|
329
|
+
await query.cache.queryGetObject(marketId, {
|
|
330
|
+
showContent: true,
|
|
331
|
+
})
|
|
332
|
+
)?.data;
|
|
336
333
|
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
334
|
+
if (!(marketObject && marketObject.content?.dataType === 'moveObject'))
|
|
335
|
+
throw new Error(`Failed to fetch marketObject`);
|
|
336
|
+
|
|
337
|
+
const fields = marketObject.content.fields as any;
|
|
338
|
+
const coinType = query.utils.parseCoinType(poolCoinName);
|
|
339
|
+
// Get balance sheet.
|
|
340
|
+
const balanceSheetParentId =
|
|
341
|
+
fields.vault.fields.balance_sheets.fields.table.fields.id.id;
|
|
342
|
+
const balanceSheetDynamicFieldObjectResponse =
|
|
343
|
+
await query.cache.queryGetDynamicFieldObject({
|
|
344
|
+
parentId: balanceSheetParentId,
|
|
345
|
+
name: {
|
|
346
|
+
type: '0x1::type_name::TypeName',
|
|
347
|
+
value: {
|
|
348
|
+
name: coinType.substring(2),
|
|
350
349
|
},
|
|
351
|
-
}
|
|
350
|
+
},
|
|
351
|
+
});
|
|
352
352
|
|
|
353
|
-
|
|
354
|
-
|
|
353
|
+
const balanceSheetDynamicFieldObject =
|
|
354
|
+
balanceSheetDynamicFieldObjectResponse?.data;
|
|
355
355
|
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
)
|
|
356
|
+
if (
|
|
357
|
+
!(
|
|
358
|
+
balanceSheetDynamicFieldObject &&
|
|
359
|
+
balanceSheetDynamicFieldObject.content &&
|
|
360
|
+
'fields' in balanceSheetDynamicFieldObject.content
|
|
362
361
|
)
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
)
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
},
|
|
362
|
+
)
|
|
363
|
+
throw new Error(
|
|
364
|
+
`Failed to fetch balanceSheetDynamicFieldObject for ${poolCoinName}: ${balanceSheetDynamicFieldObjectResponse?.error?.code.toString()}`
|
|
365
|
+
);
|
|
366
|
+
const balanceSheet: BalanceSheet = (
|
|
367
|
+
balanceSheetDynamicFieldObject.content.fields as any
|
|
368
|
+
).value.fields;
|
|
369
|
+
|
|
370
|
+
// Get borrow index.
|
|
371
|
+
const borrowIndexParentId = fields.borrow_dynamics.fields.table.fields.id.id;
|
|
372
|
+
const borrowIndexDynamicFieldObjectResponse =
|
|
373
|
+
await query.cache.queryGetDynamicFieldObject({
|
|
374
|
+
parentId: borrowIndexParentId,
|
|
375
|
+
name: {
|
|
376
|
+
type: '0x1::type_name::TypeName',
|
|
377
|
+
value: {
|
|
378
|
+
name: coinType.substring(2),
|
|
381
379
|
},
|
|
382
|
-
}
|
|
380
|
+
},
|
|
381
|
+
});
|
|
383
382
|
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
)
|
|
383
|
+
const borrowIndexDynamicFieldObject =
|
|
384
|
+
borrowIndexDynamicFieldObjectResponse?.data;
|
|
385
|
+
if (
|
|
386
|
+
!(
|
|
387
|
+
borrowIndexDynamicFieldObject &&
|
|
388
|
+
borrowIndexDynamicFieldObject.content &&
|
|
389
|
+
'fields' in borrowIndexDynamicFieldObject.content
|
|
392
390
|
)
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
391
|
+
)
|
|
392
|
+
throw new Error(
|
|
393
|
+
`Failed to fetch borrowIndexDynamicFieldObject for ${poolCoinName}`
|
|
394
|
+
);
|
|
395
|
+
const borrowIndex: BorrowIndex = (
|
|
396
|
+
borrowIndexDynamicFieldObject.content.fields as any
|
|
397
|
+
).value.fields;
|
|
398
|
+
|
|
399
|
+
// Get interest models.
|
|
400
|
+
const interestModelParentId =
|
|
401
|
+
fields.interest_models.fields.table.fields.id.id;
|
|
402
|
+
const interestModelDynamicFieldObjectResponse =
|
|
403
|
+
await query.cache.queryGetDynamicFieldObject({
|
|
404
|
+
parentId: interestModelParentId,
|
|
405
|
+
name: {
|
|
406
|
+
type: '0x1::type_name::TypeName',
|
|
407
|
+
value: {
|
|
408
|
+
name: coinType.substring(2),
|
|
409
|
+
},
|
|
410
|
+
},
|
|
411
|
+
});
|
|
412
|
+
|
|
413
|
+
const interestModelDynamicFieldObject =
|
|
414
|
+
interestModelDynamicFieldObjectResponse?.data;
|
|
415
|
+
if (
|
|
416
|
+
!(
|
|
417
|
+
interestModelDynamicFieldObject &&
|
|
418
|
+
interestModelDynamicFieldObject.content &&
|
|
419
|
+
'fields' in interestModelDynamicFieldObject.content
|
|
420
|
+
)
|
|
421
|
+
)
|
|
422
|
+
throw new Error(
|
|
423
|
+
`Failed to fetch interestModelDynamicFieldObject for ${poolCoinName}: ${interestModelDynamicFieldObject}`
|
|
424
|
+
);
|
|
425
|
+
const interestModel: InterestModel = (
|
|
426
|
+
interestModelDynamicFieldObject.content.fields as any
|
|
427
|
+
).value.fields;
|
|
428
|
+
|
|
429
|
+
// Get borrow fee.
|
|
430
|
+
const getBorrowFee = async () => {
|
|
431
|
+
const borrowFeeDynamicFieldObjectResponse =
|
|
404
432
|
await query.cache.queryGetDynamicFieldObject({
|
|
405
|
-
parentId:
|
|
433
|
+
parentId: marketId,
|
|
406
434
|
name: {
|
|
407
|
-
type:
|
|
435
|
+
type: `${BORROW_FEE_PROTOCOL_ID}::market_dynamic_keys::BorrowFeeKey`,
|
|
408
436
|
value: {
|
|
409
|
-
|
|
437
|
+
type: {
|
|
438
|
+
name: coinType.substring(2),
|
|
439
|
+
},
|
|
410
440
|
},
|
|
411
441
|
},
|
|
412
442
|
});
|
|
413
443
|
|
|
414
|
-
const
|
|
415
|
-
|
|
444
|
+
const borrowFeeDynamicFieldObject =
|
|
445
|
+
borrowFeeDynamicFieldObjectResponse?.data;
|
|
416
446
|
if (
|
|
417
447
|
!(
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
'fields' in
|
|
448
|
+
borrowFeeDynamicFieldObject &&
|
|
449
|
+
borrowFeeDynamicFieldObject.content &&
|
|
450
|
+
'fields' in borrowFeeDynamicFieldObject.content
|
|
421
451
|
)
|
|
422
452
|
)
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
const interestModel: InterestModel = (
|
|
427
|
-
interestModelDynamicFieldObject.content.fields as any
|
|
428
|
-
).value.fields;
|
|
429
|
-
|
|
430
|
-
// Get borrow fee.
|
|
431
|
-
const getBorrowFee = async () => {
|
|
432
|
-
const borrowFeeDynamicFieldObjectResponse =
|
|
433
|
-
await query.cache.queryGetDynamicFieldObject({
|
|
434
|
-
parentId: marketId,
|
|
435
|
-
name: {
|
|
436
|
-
type: `${BORROW_FEE_PROTOCOL_ID}::market_dynamic_keys::BorrowFeeKey`,
|
|
437
|
-
value: {
|
|
438
|
-
type: {
|
|
439
|
-
name: coinType.substring(2),
|
|
440
|
-
},
|
|
441
|
-
},
|
|
442
|
-
},
|
|
443
|
-
});
|
|
444
|
-
|
|
445
|
-
const borrowFeeDynamicFieldObject =
|
|
446
|
-
borrowFeeDynamicFieldObjectResponse?.data;
|
|
447
|
-
if (
|
|
448
|
-
!(
|
|
449
|
-
borrowFeeDynamicFieldObject &&
|
|
450
|
-
borrowFeeDynamicFieldObject.content &&
|
|
451
|
-
'fields' in borrowFeeDynamicFieldObject.content
|
|
452
|
-
)
|
|
453
|
-
)
|
|
454
|
-
return { value: '0' };
|
|
455
|
-
return (borrowFeeDynamicFieldObject.content.fields as any).value.fields;
|
|
456
|
-
};
|
|
453
|
+
return { value: '0' };
|
|
454
|
+
return (borrowFeeDynamicFieldObject.content.fields as any).value.fields;
|
|
455
|
+
};
|
|
457
456
|
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
457
|
+
const parsedMarketPoolData = parseOriginMarketPoolData({
|
|
458
|
+
type: interestModel.type.fields,
|
|
459
|
+
maxBorrowRate: interestModel.max_borrow_rate.fields,
|
|
460
|
+
interestRate: borrowIndex.interest_rate.fields,
|
|
461
|
+
interestRateScale: borrowIndex.interest_rate_scale,
|
|
462
|
+
borrowIndex: borrowIndex.borrow_index,
|
|
463
|
+
lastUpdated: borrowIndex.last_updated,
|
|
464
|
+
cash: balanceSheet.cash,
|
|
465
|
+
debt: balanceSheet.debt,
|
|
466
|
+
marketCoinSupply: balanceSheet.market_coin_supply,
|
|
467
|
+
reserve: balanceSheet.revenue,
|
|
468
|
+
reserveFactor: interestModel.revenue_factor.fields,
|
|
469
|
+
borrowWeight: interestModel.borrow_weight.fields,
|
|
470
|
+
borrowFeeRate: await getBorrowFee(),
|
|
471
|
+
baseBorrowRatePerSec: interestModel.base_borrow_rate_per_sec.fields,
|
|
472
|
+
borrowRateOnHighKink: interestModel.borrow_rate_on_high_kink.fields,
|
|
473
|
+
borrowRateOnMidKink: interestModel.borrow_rate_on_mid_kink.fields,
|
|
474
|
+
highKink: interestModel.high_kink.fields,
|
|
475
|
+
midKink: interestModel.mid_kink.fields,
|
|
476
|
+
minBorrowAmount: interestModel.min_borrow_amount,
|
|
477
|
+
});
|
|
479
478
|
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
479
|
+
const calculatedMarketPoolData = calculateMarketPoolData(
|
|
480
|
+
query.utils,
|
|
481
|
+
parsedMarketPoolData
|
|
482
|
+
);
|
|
484
483
|
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
484
|
+
const coinDecimal = query.utils.getCoinDecimal(poolCoinName);
|
|
485
|
+
const maxSupplyCoin = BigNumber(
|
|
486
|
+
(await getSupplyLimit(query.utils, poolCoinName)) ?? '0'
|
|
487
|
+
)
|
|
488
|
+
.shiftedBy(-coinDecimal)
|
|
489
|
+
.toNumber();
|
|
490
|
+
const maxBorrowCoin = BigNumber(
|
|
491
|
+
(await getBorrowLimit(query.utils, poolCoinName)) ?? '0'
|
|
492
|
+
)
|
|
493
|
+
.shiftedBy(-coinDecimal)
|
|
494
|
+
.toNumber();
|
|
496
495
|
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
} catch (e: any) {
|
|
521
|
-
console.error(e.message);
|
|
522
|
-
}
|
|
496
|
+
return {
|
|
497
|
+
coinName: poolCoinName,
|
|
498
|
+
symbol: query.utils.parseSymbol(poolCoinName),
|
|
499
|
+
coinType: query.utils.parseCoinType(poolCoinName),
|
|
500
|
+
marketCoinType: query.utils.parseMarketCoinType(poolCoinName),
|
|
501
|
+
sCoinType: query.utils.parseSCoinType(
|
|
502
|
+
query.utils.parseMarketCoinName(poolCoinName)
|
|
503
|
+
),
|
|
504
|
+
coinWrappedType: query.utils.getCoinWrappedType(poolCoinName),
|
|
505
|
+
coinDecimal,
|
|
506
|
+
coinPrice: coinPrice ?? 0,
|
|
507
|
+
highKink: parsedMarketPoolData.highKink,
|
|
508
|
+
midKink: parsedMarketPoolData.midKink,
|
|
509
|
+
reserveFactor: parsedMarketPoolData.reserveFactor,
|
|
510
|
+
borrowWeight: parsedMarketPoolData.borrowWeight,
|
|
511
|
+
borrowFee: parsedMarketPoolData.borrowFee,
|
|
512
|
+
marketCoinSupplyAmount: parsedMarketPoolData.marketCoinSupplyAmount,
|
|
513
|
+
minBorrowAmount: parsedMarketPoolData.minBorrowAmount,
|
|
514
|
+
maxSupplyCoin,
|
|
515
|
+
maxBorrowCoin,
|
|
516
|
+
isIsolated: await isIsolatedAsset(query.utils, poolCoinName),
|
|
517
|
+
...calculatedMarketPoolData,
|
|
518
|
+
};
|
|
523
519
|
};
|
|
524
520
|
|
|
525
521
|
/**
|
|
@@ -540,7 +536,8 @@ export const getMarketCollaterals = async (
|
|
|
540
536
|
indexer: boolean = false
|
|
541
537
|
) => {
|
|
542
538
|
const marketId = query.address.get('core.market');
|
|
543
|
-
const coinPrices =
|
|
539
|
+
const coinPrices =
|
|
540
|
+
(await query.utils.getCoinPrices(collateralCoinNames)) ?? {};
|
|
544
541
|
const marketCollaterals: MarketCollaterals = {};
|
|
545
542
|
|
|
546
543
|
if (indexer) {
|
|
@@ -598,7 +595,10 @@ export const getMarketCollateral = async (
|
|
|
598
595
|
coinPrice?: number
|
|
599
596
|
): Promise<MarketCollateral | undefined> => {
|
|
600
597
|
coinPrice =
|
|
601
|
-
coinPrice
|
|
598
|
+
coinPrice ||
|
|
599
|
+
(await query.utils.getCoinPrices([collateralCoinName]))?.[
|
|
600
|
+
collateralCoinName
|
|
601
|
+
];
|
|
602
602
|
|
|
603
603
|
if (indexer) {
|
|
604
604
|
const marketCollateralIndexer =
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import BigNumber from 'bignumber.js';
|
|
2
2
|
import {
|
|
3
|
+
SUPPORT_BORROW_INCENTIVE_REWARDS,
|
|
3
4
|
SUPPORT_COLLATERALS,
|
|
4
5
|
SUPPORT_POOLS,
|
|
5
6
|
SUPPORT_SPOOLS,
|
|
@@ -49,11 +50,13 @@ export const getLendings = async (
|
|
|
49
50
|
(SUPPORT_SPOOLS as readonly SupportMarketCoins[]).includes(marketCoinName)
|
|
50
51
|
) as SupportStakeMarketCoins[];
|
|
51
52
|
|
|
52
|
-
const coinPrices = await query.utils.getCoinPrices();
|
|
53
|
-
const marketPools = await query.getMarketPools(poolCoinNames,
|
|
53
|
+
const coinPrices = await query.utils.getCoinPrices(poolCoinNames);
|
|
54
|
+
const marketPools = await query.getMarketPools(poolCoinNames, {
|
|
55
|
+
indexer,
|
|
54
56
|
coinPrices,
|
|
55
57
|
});
|
|
56
|
-
const spools = await query.getSpools(stakeMarketCoinNames,
|
|
58
|
+
const spools = await query.getSpools(stakeMarketCoinNames, {
|
|
59
|
+
indexer,
|
|
57
60
|
marketPools,
|
|
58
61
|
coinPrices,
|
|
59
62
|
});
|
|
@@ -121,11 +124,14 @@ export const getLending = async (
|
|
|
121
124
|
) => {
|
|
122
125
|
const marketCoinName = query.utils.parseMarketCoinName(poolCoinName);
|
|
123
126
|
coinPrice =
|
|
124
|
-
coinPrice ??
|
|
127
|
+
coinPrice ??
|
|
128
|
+
(await query.utils.getCoinPrices([poolCoinName]))?.[poolCoinName] ??
|
|
129
|
+
0;
|
|
125
130
|
|
|
126
131
|
marketPool =
|
|
127
132
|
marketPool ??
|
|
128
|
-
(await query.getMarketPool(poolCoinName,
|
|
133
|
+
(await query.getMarketPool(poolCoinName, {
|
|
134
|
+
indexer,
|
|
129
135
|
coinPrice,
|
|
130
136
|
}));
|
|
131
137
|
|
|
@@ -135,16 +141,13 @@ export const getLending = async (
|
|
|
135
141
|
spool =
|
|
136
142
|
(spool ??
|
|
137
143
|
(SUPPORT_SPOOLS as readonly SupportMarketCoins[]).includes(marketCoinName))
|
|
138
|
-
? await query.getSpool(
|
|
139
|
-
marketCoinName as SupportStakeMarketCoins,
|
|
144
|
+
? await query.getSpool(marketCoinName as SupportStakeMarketCoins, {
|
|
140
145
|
indexer,
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
}
|
|
147
|
-
)
|
|
146
|
+
marketPool,
|
|
147
|
+
coinPrices: {
|
|
148
|
+
[poolCoinName]: coinPrice,
|
|
149
|
+
},
|
|
150
|
+
})
|
|
148
151
|
: undefined;
|
|
149
152
|
// some pool does not have spool
|
|
150
153
|
// if (!spool) throw new Error(`Failed to fetch spool for ${poolCoinName}`);
|
|
@@ -308,7 +311,7 @@ export const getObligationAccounts = async (
|
|
|
308
311
|
indexer: boolean = false
|
|
309
312
|
) => {
|
|
310
313
|
const coinPrices = await query.utils.getCoinPrices();
|
|
311
|
-
const market = await query.queryMarket(indexer,
|
|
314
|
+
const market = await query.queryMarket({ indexer, coinPrices });
|
|
312
315
|
const [coinAmounts, obligations] = await Promise.all([
|
|
313
316
|
query.getCoinAmounts(undefined, ownerAddress),
|
|
314
317
|
query.getObligations(ownerAddress),
|
|
@@ -352,9 +355,9 @@ export const getObligationAccount = async (
|
|
|
352
355
|
const collateralAssetCoinNames: SupportCollateralCoins[] = [
|
|
353
356
|
...SUPPORT_COLLATERALS,
|
|
354
357
|
];
|
|
355
|
-
market = market ?? (await query.queryMarket(indexer));
|
|
356
358
|
coinPrices =
|
|
357
|
-
coinPrices ?? (await query.
|
|
359
|
+
coinPrices ?? (await query.utils.getCoinPrices(collateralAssetCoinNames));
|
|
360
|
+
market = market ?? (await query.queryMarket({ indexer, coinPrices }));
|
|
358
361
|
coinAmounts =
|
|
359
362
|
coinAmounts ||
|
|
360
363
|
(await query.getCoinAmounts(collateralAssetCoinNames, ownerAddress));
|
|
@@ -362,8 +365,9 @@ export const getObligationAccount = async (
|
|
|
362
365
|
const [obligationQuery, borrowIncentivePools, borrowIncentiveAccounts] =
|
|
363
366
|
await Promise.all([
|
|
364
367
|
query.queryObligation(obligationId),
|
|
365
|
-
query.getBorrowIncentivePools(undefined,
|
|
368
|
+
query.getBorrowIncentivePools(undefined, {
|
|
366
369
|
coinPrices,
|
|
370
|
+
indexer,
|
|
367
371
|
}),
|
|
368
372
|
query.getBorrowIncentiveAccounts(obligationId),
|
|
369
373
|
]);
|
|
@@ -522,70 +526,64 @@ export const getObligationAccount = async (
|
|
|
522
526
|
const borrowIncentivePool = borrowIncentivePools[coinName];
|
|
523
527
|
if (borrowIncentivePool) {
|
|
524
528
|
const rewards: ObligationBorrowIcentiveReward[] = [];
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
? Math.max(
|
|
541
|
-
BigNumber(poolPoint.currentPointIndex - accountPoint.index)
|
|
542
|
-
.dividedBy(baseIndexRate)
|
|
543
|
-
.toNumber(),
|
|
544
|
-
0
|
|
545
|
-
)
|
|
546
|
-
: 1;
|
|
547
|
-
availableClaimAmount = availableClaimAmount.plus(
|
|
548
|
-
accountBorrowedAmount
|
|
549
|
-
.multipliedBy(increasedPointRate)
|
|
550
|
-
.plus(accountPoint.points)
|
|
551
|
-
);
|
|
552
|
-
availableClaimCoin = availableClaimAmount.shiftedBy(
|
|
553
|
-
-1 * poolPoint.coinDecimal
|
|
554
|
-
);
|
|
555
|
-
|
|
556
|
-
// for veSCA
|
|
557
|
-
const weightScale = BigNumber(1_000_000_000_000);
|
|
558
|
-
const boostValue = BigNumber(accountPoint.weightedAmount)
|
|
559
|
-
.div(
|
|
560
|
-
BigNumber(borrowIncentiveAccount.debtAmount)
|
|
561
|
-
.multipliedBy(poolPoint.baseWeight)
|
|
562
|
-
.dividedBy(weightScale)
|
|
529
|
+
for (const rewardCoinName of SUPPORT_BORROW_INCENTIVE_REWARDS) {
|
|
530
|
+
const accountPoint = borrowIncentiveAccount.pointList[rewardCoinName];
|
|
531
|
+
const poolPoint = borrowIncentivePool.points[rewardCoinName];
|
|
532
|
+
|
|
533
|
+
if (accountPoint && poolPoint) {
|
|
534
|
+
let availableClaimAmount = BigNumber(0);
|
|
535
|
+
let availableClaimCoin = BigNumber(0);
|
|
536
|
+
const accountBorrowedAmount = BigNumber(accountPoint.weightedAmount);
|
|
537
|
+
const baseIndexRate = 1_000_000_000;
|
|
538
|
+
const increasedPointRate = poolPoint.currentPointIndex
|
|
539
|
+
? Math.max(
|
|
540
|
+
BigNumber(poolPoint.currentPointIndex - accountPoint.index)
|
|
541
|
+
.dividedBy(baseIndexRate)
|
|
542
|
+
.toNumber(),
|
|
543
|
+
0
|
|
563
544
|
)
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
545
|
+
: 1;
|
|
546
|
+
availableClaimAmount = availableClaimAmount.plus(
|
|
547
|
+
accountBorrowedAmount
|
|
548
|
+
.multipliedBy(increasedPointRate)
|
|
549
|
+
.plus(accountPoint.points)
|
|
550
|
+
);
|
|
551
|
+
availableClaimCoin = availableClaimAmount.shiftedBy(
|
|
552
|
+
-1 * poolPoint.coinDecimal
|
|
553
|
+
);
|
|
554
|
+
|
|
555
|
+
// for veSCA
|
|
556
|
+
const weightScale = BigNumber(1_000_000_000_000);
|
|
557
|
+
const boostValue = BigNumber(accountPoint.weightedAmount)
|
|
558
|
+
.div(
|
|
559
|
+
BigNumber(borrowIncentiveAccount.debtAmount)
|
|
560
|
+
.multipliedBy(poolPoint.baseWeight)
|
|
561
|
+
.dividedBy(weightScale)
|
|
562
|
+
)
|
|
563
|
+
.isFinite()
|
|
564
|
+
? BigNumber(accountPoint.weightedAmount)
|
|
565
|
+
.div(
|
|
566
|
+
BigNumber(borrowIncentiveAccount.debtAmount)
|
|
567
|
+
.multipliedBy(poolPoint.baseWeight)
|
|
568
|
+
.dividedBy(weightScale)
|
|
569
|
+
)
|
|
570
|
+
.toNumber()
|
|
571
|
+
: 1;
|
|
572
|
+
|
|
573
|
+
if (availableClaimAmount.isGreaterThanOrEqualTo(0)) {
|
|
574
|
+
rewards.push({
|
|
575
|
+
coinName: poolPoint.coinName,
|
|
576
|
+
coinType: poolPoint.coinType,
|
|
577
|
+
symbol: poolPoint.symbol,
|
|
578
|
+
coinDecimal: poolPoint.coinDecimal,
|
|
579
|
+
coinPrice: poolPoint.coinPrice,
|
|
580
|
+
availableClaimAmount: availableClaimAmount.toNumber(),
|
|
581
|
+
availableClaimCoin: availableClaimCoin.toNumber(),
|
|
582
|
+
boostValue,
|
|
583
|
+
});
|
|
586
584
|
}
|
|
587
585
|
}
|
|
588
|
-
|
|
586
|
+
}
|
|
589
587
|
|
|
590
588
|
if (
|
|
591
589
|
Object.keys(borrowIncentivePool.points).some((coinName: any) => {
|
|
@@ -773,7 +771,7 @@ export const getTotalValueLocked = async (
|
|
|
773
771
|
query: ScallopQuery,
|
|
774
772
|
indexer: boolean = false
|
|
775
773
|
) => {
|
|
776
|
-
const market = await query.queryMarket(indexer);
|
|
774
|
+
const market = await query.queryMarket({ indexer });
|
|
777
775
|
|
|
778
776
|
let supplyValue = BigNumber(0);
|
|
779
777
|
let borrowValue = BigNumber(0);
|