@scallop-io/sui-scallop-sdk 2.2.6 → 2.2.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/index.d.mts +39 -3
- package/dist/index.d.ts +39 -3
- package/dist/index.js +24 -24
- package/dist/index.mjs +4 -4
- package/package.json +1 -1
- package/src/models/scallopQuery.ts +75 -3
- package/src/queries/portfolioQuery.ts +54 -2
package/package.json
CHANGED
|
@@ -30,7 +30,9 @@ import {
|
|
|
30
30
|
getMarketCollateral,
|
|
31
31
|
getMarketCollaterals,
|
|
32
32
|
getMarketPools,
|
|
33
|
+
getObligationAccount,
|
|
33
34
|
getObligationAccounts,
|
|
35
|
+
getObligationAccountsByIds,
|
|
34
36
|
getObligations,
|
|
35
37
|
getOnDemandAggObjectIds,
|
|
36
38
|
getPoolAddresses,
|
|
@@ -108,6 +110,14 @@ class ScallopQuery implements ScallopQueryInterface {
|
|
|
108
110
|
this,
|
|
109
111
|
this.getObligationAccounts
|
|
110
112
|
);
|
|
113
|
+
this.getObligationAccountsByIds = withIndexerFallback.call(
|
|
114
|
+
this,
|
|
115
|
+
this.getObligationAccountsByIds
|
|
116
|
+
);
|
|
117
|
+
this.getObligationAccountById = withIndexerFallback.call(
|
|
118
|
+
this,
|
|
119
|
+
this.getObligationAccountById
|
|
120
|
+
);
|
|
111
121
|
this.getObligationAccount = withIndexerFallback.call(
|
|
112
122
|
this,
|
|
113
123
|
this.getObligationAccount
|
|
@@ -558,13 +568,13 @@ class ScallopQuery implements ScallopQueryInterface {
|
|
|
558
568
|
}
|
|
559
569
|
|
|
560
570
|
/**
|
|
561
|
-
* Get user all obligation accounts information.
|
|
571
|
+
* Get user all obligation accounts information from ownerAddress.
|
|
562
572
|
*
|
|
563
573
|
* @description
|
|
564
574
|
* All collateral and borrowing information in all obligation accounts owned by the user.
|
|
565
575
|
*
|
|
566
576
|
* @param ownerAddress - The owner address.
|
|
567
|
-
* @param
|
|
577
|
+
* @param args - Additional arguments.
|
|
568
578
|
* @return All obligation accounts information.
|
|
569
579
|
*/
|
|
570
580
|
async getObligationAccounts(
|
|
@@ -587,6 +597,68 @@ class ScallopQuery implements ScallopQueryInterface {
|
|
|
587
597
|
);
|
|
588
598
|
}
|
|
589
599
|
|
|
600
|
+
/**
|
|
601
|
+
* Get user all obligation accounts information from obligationIds.
|
|
602
|
+
*
|
|
603
|
+
* @description
|
|
604
|
+
* All collateral and borrowing information in all obligation accounts.
|
|
605
|
+
*
|
|
606
|
+
* @param obligationIds - Obligation IDs.
|
|
607
|
+
* @param args - Additional arguments.
|
|
608
|
+
* @return All obligation accounts information.
|
|
609
|
+
*/
|
|
610
|
+
async getObligationAccountsByIds(
|
|
611
|
+
obligationIds: string[],
|
|
612
|
+
args?: {
|
|
613
|
+
market?: {
|
|
614
|
+
collaterals: MarketCollaterals;
|
|
615
|
+
pools: MarketPools;
|
|
616
|
+
};
|
|
617
|
+
coinPrices?: CoinPrices;
|
|
618
|
+
indexer?: boolean;
|
|
619
|
+
}
|
|
620
|
+
) {
|
|
621
|
+
return await getObligationAccountsByIds(
|
|
622
|
+
this,
|
|
623
|
+
obligationIds,
|
|
624
|
+
args?.market,
|
|
625
|
+
args?.coinPrices,
|
|
626
|
+
args?.indexer
|
|
627
|
+
);
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
/**
|
|
631
|
+
* Get obligation account by id
|
|
632
|
+
*
|
|
633
|
+
* @description
|
|
634
|
+
* All collateral and borrowing information in obligation account.
|
|
635
|
+
*
|
|
636
|
+
* @param obligationId - Obligation ID.
|
|
637
|
+
* @param args - Additional arguments.
|
|
638
|
+
* @return All obligation accounts information.
|
|
639
|
+
*/
|
|
640
|
+
async getObligationAccountById(
|
|
641
|
+
obligationId: string,
|
|
642
|
+
args?: {
|
|
643
|
+
market?: {
|
|
644
|
+
collaterals: MarketCollaterals;
|
|
645
|
+
pools: MarketPools;
|
|
646
|
+
};
|
|
647
|
+
coinPrices?: CoinPrices;
|
|
648
|
+
indexer?: boolean;
|
|
649
|
+
}
|
|
650
|
+
) {
|
|
651
|
+
return await getObligationAccount(
|
|
652
|
+
this,
|
|
653
|
+
obligationId,
|
|
654
|
+
'',
|
|
655
|
+
args?.indexer,
|
|
656
|
+
args?.market,
|
|
657
|
+
args?.coinPrices,
|
|
658
|
+
{}
|
|
659
|
+
);
|
|
660
|
+
}
|
|
661
|
+
|
|
590
662
|
/**
|
|
591
663
|
* Get obligation account information for specific id.
|
|
592
664
|
*
|
|
@@ -595,7 +667,7 @@ class ScallopQuery implements ScallopQueryInterface {
|
|
|
595
667
|
*
|
|
596
668
|
* @param obligationId - The obligation id.
|
|
597
669
|
* @param ownerAddress - The owner address.
|
|
598
|
-
* @param
|
|
670
|
+
* @param args - Additional arguments.
|
|
599
671
|
* @return Borrowing and collateral information.
|
|
600
672
|
*/
|
|
601
673
|
async getObligationAccount(
|
|
@@ -293,6 +293,8 @@ export const getLending = async (
|
|
|
293
293
|
*
|
|
294
294
|
* @param query - The Scallop query instance.
|
|
295
295
|
* @param ownerAddress - The owner address.
|
|
296
|
+
* @param market - The market data.
|
|
297
|
+
* @param coinPrices - The coin prices data.
|
|
296
298
|
* @param indexer - Whether to use indexer.
|
|
297
299
|
* @return All obligation accounts data.
|
|
298
300
|
*/
|
|
@@ -338,12 +340,62 @@ export const getObligationAccounts = async (
|
|
|
338
340
|
return obligationAccounts;
|
|
339
341
|
};
|
|
340
342
|
|
|
343
|
+
/**
|
|
344
|
+
* Get all obligation accounts data by ids.
|
|
345
|
+
*
|
|
346
|
+
* @param query - The Scallop query instance.
|
|
347
|
+
* @param obligationIds - Obligation account ids.
|
|
348
|
+
* @param market - The market data.
|
|
349
|
+
* @param coinPrices - The coin prices data.
|
|
350
|
+
* @param indexer - Whether to use indexer.
|
|
351
|
+
* @return All obligation accounts data.
|
|
352
|
+
*/
|
|
353
|
+
export const getObligationAccountsByIds = async (
|
|
354
|
+
query: ScallopQuery,
|
|
355
|
+
obligationIds: string[],
|
|
356
|
+
market?: {
|
|
357
|
+
pools: MarketPools;
|
|
358
|
+
collaterals: MarketCollaterals;
|
|
359
|
+
},
|
|
360
|
+
coinPrices?: CoinPrices,
|
|
361
|
+
indexer: boolean = false
|
|
362
|
+
) => {
|
|
363
|
+
market = market ?? (await query.getMarketPools(undefined, { indexer }));
|
|
364
|
+
coinPrices =
|
|
365
|
+
coinPrices ??
|
|
366
|
+
(await query.getAllCoinPrices({
|
|
367
|
+
marketPools: market.pools,
|
|
368
|
+
}));
|
|
369
|
+
|
|
370
|
+
const obligationAccounts: ObligationAccount[] = [];
|
|
371
|
+
await Promise.allSettled(
|
|
372
|
+
obligationIds.map(async (obligationId) => {
|
|
373
|
+
const obligationAccount = await getObligationAccount(
|
|
374
|
+
query,
|
|
375
|
+
obligationId,
|
|
376
|
+
'',
|
|
377
|
+
indexer,
|
|
378
|
+
market,
|
|
379
|
+
coinPrices,
|
|
380
|
+
{}
|
|
381
|
+
);
|
|
382
|
+
if (obligationAccount) obligationAccounts.push(obligationAccount);
|
|
383
|
+
})
|
|
384
|
+
);
|
|
385
|
+
|
|
386
|
+
return obligationAccounts;
|
|
387
|
+
};
|
|
388
|
+
|
|
341
389
|
/**
|
|
342
390
|
* Get obligation account data.
|
|
343
391
|
*
|
|
344
392
|
* @param query - The Scallop query instance.
|
|
345
393
|
* @param obligation - The obligation id.
|
|
394
|
+
* @param ownerAddress - The owner address of the obligation.
|
|
346
395
|
* @param indexer - Whether to use indexer.
|
|
396
|
+
* @param market - The market data.
|
|
397
|
+
* @param coinPrices - The coin prices data.
|
|
398
|
+
* @param coinAmounts - The coin amounts data.
|
|
347
399
|
* @return Obligation account data.
|
|
348
400
|
*/
|
|
349
401
|
export const getObligationAccount = async (
|
|
@@ -787,8 +839,6 @@ export const getTotalValueLocked = async (
|
|
|
787
839
|
query: ScallopQuery,
|
|
788
840
|
indexer: boolean = false
|
|
789
841
|
) => {
|
|
790
|
-
const market = await query.getMarketPools(undefined, { indexer });
|
|
791
|
-
|
|
792
842
|
let supplyLendingValue = BigNumber(0);
|
|
793
843
|
let supplyCollateralValue = BigNumber(0);
|
|
794
844
|
let borrowValue = BigNumber(0);
|
|
@@ -811,6 +861,8 @@ export const getTotalValueLocked = async (
|
|
|
811
861
|
return tvl;
|
|
812
862
|
}
|
|
813
863
|
|
|
864
|
+
const market = await query.getMarketPools(undefined, { indexer });
|
|
865
|
+
|
|
814
866
|
for (const pool of Object.values(market.pools)) {
|
|
815
867
|
if (!pool) continue;
|
|
816
868
|
supplyLendingValue = supplyLendingValue.plus(
|