@scallop-io/sui-scallop-sdk 1.4.3-rc.1 → 1.4.4
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.js +11 -7
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +11 -7
- package/dist/index.mjs.map +1 -1
- package/dist/models/scallopQuery.d.ts +4 -3
- package/dist/queries/borrowIncentiveQuery.d.ts +2 -1
- package/dist/queries/portfolioQuery.d.ts +3 -2
- package/package.json +1 -1
- package/src/models/scallopQuery.ts +4 -3
- package/src/queries/borrowIncentiveQuery.ts +2 -1
- package/src/queries/portfolioQuery.ts +15 -10
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { SuiKit } from '@scallop-io/sui-kit';
|
|
1
|
+
import { SuiKit, SuiObjectArg } from '@scallop-io/sui-kit';
|
|
2
2
|
import { ScallopQueryParams, SupportStakeMarketCoins, SupportAssetCoins, SupportPoolCoins, SupportCollateralCoins, SupportMarketCoins, SupportBorrowIncentiveCoins, SupportSCoin, ScallopQueryInstanceParams, MarketPool, CoinPrices, MarketPools } from '../types';
|
|
3
3
|
import { ScallopAddress } from './scallopAddress';
|
|
4
4
|
import { ScallopUtils } from './scallopUtils';
|
|
5
5
|
import { ScallopIndexer } from './scallopIndexer';
|
|
6
6
|
import { ScallopCache } from './scallopCache';
|
|
7
7
|
import { SuiObjectData } from '@mysten/sui/client';
|
|
8
|
+
import { SuiObjectRef } from '@mysten/sui/client';
|
|
8
9
|
/**
|
|
9
10
|
* @description
|
|
10
11
|
* It provides methods for getting on-chain data from the Scallop contract.
|
|
@@ -124,7 +125,7 @@ export declare class ScallopQuery {
|
|
|
124
125
|
* @param obligationId - The obligation id.
|
|
125
126
|
* @return Obligation data.
|
|
126
127
|
*/
|
|
127
|
-
queryObligation(obligationId: string): Promise<import("../types").ObligationQueryInterface | undefined>;
|
|
128
|
+
queryObligation(obligationId: string | SuiObjectArg): Promise<import("../types").ObligationQueryInterface | undefined>;
|
|
128
129
|
/**
|
|
129
130
|
* Get all asset coin amounts.
|
|
130
131
|
*
|
|
@@ -320,7 +321,7 @@ export declare class ScallopQuery {
|
|
|
320
321
|
* @param ownerAddress - The owner address.
|
|
321
322
|
* @return Borrow incentive accounts data.
|
|
322
323
|
*/
|
|
323
|
-
getBorrowIncentiveAccounts(obligationId: string, coinNames?: SupportBorrowIncentiveCoins[]): Promise<{
|
|
324
|
+
getBorrowIncentiveAccounts(obligationId: string | SuiObjectRef, coinNames?: SupportBorrowIncentiveCoins[]): Promise<{
|
|
324
325
|
usdc?: import("../types").ParsedBorrowIncentiveAccountData | undefined;
|
|
325
326
|
sbeth?: import("../types").ParsedBorrowIncentiveAccountData | undefined;
|
|
326
327
|
weth?: import("../types").ParsedBorrowIncentiveAccountData | undefined;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { ScallopAddress, ScallopQuery, ScallopUtils } from '../models';
|
|
2
2
|
import type { BorrowIncentivePoolsQueryInterface, SupportBorrowIncentiveCoins, BorrowIncentivePool, CoinPrices, MarketPools } from '../types';
|
|
3
|
+
import { SuiObjectRef } from '@mysten/sui/client';
|
|
3
4
|
/**
|
|
4
5
|
* Query borrow incentive pools data using moveCall
|
|
5
6
|
* @param address
|
|
@@ -41,7 +42,7 @@ export declare const getBorrowIncentivePools: (query: ScallopQuery, borrowIncent
|
|
|
41
42
|
*/
|
|
42
43
|
export declare const queryBorrowIncentiveAccounts: ({ utils, }: {
|
|
43
44
|
utils: ScallopUtils;
|
|
44
|
-
}, obligationId: string, borrowIncentiveCoinNames?: SupportBorrowIncentiveCoins[]) => Promise<{
|
|
45
|
+
}, obligationId: string | SuiObjectRef, borrowIncentiveCoinNames?: SupportBorrowIncentiveCoins[]) => Promise<{
|
|
45
46
|
usdc?: import("../types").ParsedBorrowIncentiveAccountData | undefined;
|
|
46
47
|
sbeth?: import("../types").ParsedBorrowIncentiveAccountData | undefined;
|
|
47
48
|
weth?: import("../types").ParsedBorrowIncentiveAccountData | undefined;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { ScallopQuery } from '../models';
|
|
2
2
|
import type { Market, SupportPoolCoins, MarketPool, Spool, StakeAccount, Lending, ObligationAccount, CoinAmounts, CoinPrices, TotalValueLocked } from '../types';
|
|
3
|
+
import { SuiObjectRef } from '@mysten/sui/client';
|
|
3
4
|
/**
|
|
4
5
|
* Get user lending infomation for specific pools.
|
|
5
6
|
*
|
|
@@ -60,11 +61,11 @@ export declare const getObligationAccounts: (query: ScallopQuery, ownerAddress?:
|
|
|
60
61
|
* Get obligation account data.
|
|
61
62
|
*
|
|
62
63
|
* @param query - The Scallop query instance.
|
|
63
|
-
* @param
|
|
64
|
+
* @param obligation - The obligation id.
|
|
64
65
|
* @param indexer - Whether to use indexer.
|
|
65
66
|
* @return Obligation account data.
|
|
66
67
|
*/
|
|
67
|
-
export declare const getObligationAccount: (query: ScallopQuery,
|
|
68
|
+
export declare const getObligationAccount: (query: ScallopQuery, obligation: string | SuiObjectRef, ownerAddress?: string, indexer?: boolean, market?: Market, coinPrices?: CoinPrices, coinAmounts?: CoinAmounts) => Promise<ObligationAccount>;
|
|
68
69
|
/**
|
|
69
70
|
* Get total value locked data.
|
|
70
71
|
*
|
package/package.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SuiKit } from '@scallop-io/sui-kit';
|
|
1
|
+
import { SuiKit, SuiObjectArg } from '@scallop-io/sui-kit';
|
|
2
2
|
import {
|
|
3
3
|
ADDRESSES_ID,
|
|
4
4
|
SUPPORT_POOLS,
|
|
@@ -72,6 +72,7 @@ import { SuiObjectData } from '@mysten/sui/client';
|
|
|
72
72
|
import { normalizeSuiAddress } from '@mysten/sui/utils';
|
|
73
73
|
import { withIndexerFallback } from 'src/utils/indexer';
|
|
74
74
|
import { newSuiKit } from './suiKit';
|
|
75
|
+
import { SuiObjectRef } from '@mysten/sui/client';
|
|
75
76
|
/**
|
|
76
77
|
* @description
|
|
77
78
|
* It provides methods for getting on-chain data from the Scallop contract.
|
|
@@ -298,7 +299,7 @@ export class ScallopQuery {
|
|
|
298
299
|
* @param obligationId - The obligation id.
|
|
299
300
|
* @return Obligation data.
|
|
300
301
|
*/
|
|
301
|
-
public async queryObligation(obligationId: string) {
|
|
302
|
+
public async queryObligation(obligationId: string | SuiObjectArg) {
|
|
302
303
|
return queryObligation(this, obligationId);
|
|
303
304
|
}
|
|
304
305
|
|
|
@@ -564,7 +565,7 @@ export class ScallopQuery {
|
|
|
564
565
|
* @return Borrow incentive accounts data.
|
|
565
566
|
*/
|
|
566
567
|
public async getBorrowIncentiveAccounts(
|
|
567
|
-
obligationId: string,
|
|
568
|
+
obligationId: string | SuiObjectRef,
|
|
568
569
|
coinNames?: SupportBorrowIncentiveCoins[]
|
|
569
570
|
) {
|
|
570
571
|
return await queryBorrowIncentiveAccounts(this, obligationId, coinNames);
|
|
@@ -23,6 +23,7 @@ import type {
|
|
|
23
23
|
MarketPools,
|
|
24
24
|
} from '../types';
|
|
25
25
|
import BigNumber from 'bignumber.js';
|
|
26
|
+
import { SuiObjectRef } from '@mysten/sui/client';
|
|
26
27
|
|
|
27
28
|
/**
|
|
28
29
|
* Query borrow incentive pools data using moveCall
|
|
@@ -188,7 +189,7 @@ export const queryBorrowIncentiveAccounts = async (
|
|
|
188
189
|
}: {
|
|
189
190
|
utils: ScallopUtils;
|
|
190
191
|
},
|
|
191
|
-
obligationId: string,
|
|
192
|
+
obligationId: string | SuiObjectRef,
|
|
192
193
|
borrowIncentiveCoinNames: SupportBorrowIncentiveCoins[] = [
|
|
193
194
|
...SUPPORT_BORROW_INCENTIVE_POOLS,
|
|
194
195
|
]
|
|
@@ -27,6 +27,8 @@ import type {
|
|
|
27
27
|
SupportBorrowIncentiveRewardCoins,
|
|
28
28
|
SupportAssetCoins,
|
|
29
29
|
} from '../types';
|
|
30
|
+
import { SuiObjectRef } from '@mysten/sui/client';
|
|
31
|
+
import { queryMultipleObjects } from './objectsQuery';
|
|
30
32
|
|
|
31
33
|
/**
|
|
32
34
|
* Get user lending infomation for specific pools.
|
|
@@ -311,7 +313,7 @@ export const getObligationAccounts = async (
|
|
|
311
313
|
ownerAddress?: string,
|
|
312
314
|
indexer: boolean = false
|
|
313
315
|
) => {
|
|
314
|
-
const market = await query.
|
|
316
|
+
const market = await query.getMarketPools(undefined, { indexer });
|
|
315
317
|
const coinPrices = await query.getAllCoinPrices({
|
|
316
318
|
marketPools: market.pools,
|
|
317
319
|
});
|
|
@@ -320,12 +322,16 @@ export const getObligationAccounts = async (
|
|
|
320
322
|
query.getObligations(ownerAddress),
|
|
321
323
|
]);
|
|
322
324
|
|
|
325
|
+
const obligationObjects = await queryMultipleObjects(
|
|
326
|
+
query.cache,
|
|
327
|
+
obligations.map((obligation) => obligation.id)
|
|
328
|
+
);
|
|
323
329
|
const obligationAccounts: ObligationAccounts = {};
|
|
324
330
|
await Promise.allSettled(
|
|
325
|
-
obligations.map(async (obligation) => {
|
|
331
|
+
obligations.map(async (obligation, idx) => {
|
|
326
332
|
obligationAccounts[obligation.keyId] = await getObligationAccount(
|
|
327
333
|
query,
|
|
328
|
-
obligation.id,
|
|
334
|
+
obligationObjects[idx] ?? obligation.id,
|
|
329
335
|
ownerAddress,
|
|
330
336
|
indexer,
|
|
331
337
|
market,
|
|
@@ -342,13 +348,13 @@ export const getObligationAccounts = async (
|
|
|
342
348
|
* Get obligation account data.
|
|
343
349
|
*
|
|
344
350
|
* @param query - The Scallop query instance.
|
|
345
|
-
* @param
|
|
351
|
+
* @param obligation - The obligation id.
|
|
346
352
|
* @param indexer - Whether to use indexer.
|
|
347
353
|
* @return Obligation account data.
|
|
348
354
|
*/
|
|
349
355
|
export const getObligationAccount = async (
|
|
350
356
|
query: ScallopQuery,
|
|
351
|
-
|
|
357
|
+
obligation: string | SuiObjectRef,
|
|
352
358
|
ownerAddress?: string,
|
|
353
359
|
indexer: boolean = false,
|
|
354
360
|
market?: Market,
|
|
@@ -362,7 +368,6 @@ export const getObligationAccount = async (
|
|
|
362
368
|
...SUPPORT_COLLATERALS,
|
|
363
369
|
] as SupportCollateralCoins[];
|
|
364
370
|
|
|
365
|
-
// market = market ?? (await query.queryMarket({ indexer }));
|
|
366
371
|
market = market ?? (await query.getMarketPools(undefined, { indexer }));
|
|
367
372
|
coinPrices =
|
|
368
373
|
coinPrices ?? (await query.getAllCoinPrices({ marketPools: market.pools }));
|
|
@@ -371,13 +376,13 @@ export const getObligationAccount = async (
|
|
|
371
376
|
|
|
372
377
|
const [obligationQuery, borrowIncentivePools, borrowIncentiveAccounts] =
|
|
373
378
|
await Promise.all([
|
|
374
|
-
query.queryObligation(
|
|
379
|
+
query.queryObligation(obligation),
|
|
375
380
|
query.getBorrowIncentivePools(undefined, {
|
|
376
381
|
coinPrices,
|
|
377
382
|
indexer,
|
|
378
383
|
marketPools: market.pools,
|
|
379
384
|
}),
|
|
380
|
-
query.getBorrowIncentiveAccounts(
|
|
385
|
+
query.getBorrowIncentiveAccounts(obligation),
|
|
381
386
|
]);
|
|
382
387
|
|
|
383
388
|
const collaterals: ObligationAccount['collaterals'] = {};
|
|
@@ -657,7 +662,8 @@ export const getObligationAccount = async (
|
|
|
657
662
|
: BigNumber(0);
|
|
658
663
|
|
|
659
664
|
const obligationAccount: ObligationAccount = {
|
|
660
|
-
obligationId:
|
|
665
|
+
obligationId:
|
|
666
|
+
typeof obligation === 'string' ? obligation : obligation.objectId,
|
|
661
667
|
// Deposited collateral value (collateral balance)
|
|
662
668
|
totalDepositedValue: totalDepositedValue.toNumber(),
|
|
663
669
|
// Borrowed debt value (liabilities balance)
|
|
@@ -790,7 +796,6 @@ export const getTotalValueLocked = async (
|
|
|
790
796
|
query: ScallopQuery,
|
|
791
797
|
indexer: boolean = false
|
|
792
798
|
) => {
|
|
793
|
-
// const market = await query.queryMarket({ indexer });
|
|
794
799
|
const market = await query.getMarketPools(undefined, { indexer });
|
|
795
800
|
|
|
796
801
|
let supplyValue = BigNumber(0);
|