@scallop-io/sui-scallop-sdk 1.4.15-rc.2 → 1.4.16
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 +6 -6
- package/dist/constants/enum.d.ts +2 -2
- package/dist/constants/index.d.ts +0 -1
- package/dist/constants/poolAddress.d.ts +2 -0
- package/dist/constants/queryKeys.d.ts +3 -4
- package/dist/index.d.ts +0 -1
- package/dist/index.js +2087 -1617
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2054 -1579
- package/dist/index.mjs.map +1 -1
- package/dist/models/scallop.d.ts +1 -2
- package/dist/models/scallopBuilder.d.ts +2 -1
- package/dist/models/scallopCache.d.ts +18 -12
- package/dist/models/scallopQuery.d.ts +98 -11
- package/dist/models/scallopUtils.d.ts +4 -4
- package/dist/queries/borrowIncentiveQuery.d.ts +6 -1
- package/dist/queries/coreQuery.d.ts +2 -0
- package/dist/queries/objectsQuery.d.ts +1 -2
- package/dist/queries/poolAddressesQuery.d.ts +5 -1
- package/dist/queries/portfolioQuery.d.ts +71 -5
- package/dist/queries/priceQuery.d.ts +4 -0
- package/dist/queries/sCoinQuery.d.ts +1 -1
- package/dist/types/builder/core.d.ts +6 -6
- package/dist/types/model.d.ts +8 -2
- package/dist/utils/index.d.ts +0 -2
- package/package.json +7 -7
- package/src/builders/borrowIncentiveBuilder.ts +11 -5
- package/src/builders/coreBuilder.ts +62 -33
- package/src/builders/loyaltyProgramBuilder.ts +3 -2
- package/src/builders/referralBuilder.ts +16 -6
- package/src/builders/sCoinBuilder.ts +6 -4
- package/src/builders/spoolBuilder.ts +14 -7
- package/src/builders/vescaBuilder.ts +13 -7
- package/src/constants/coinGecko.ts +2 -0
- package/src/constants/common.ts +7 -1
- package/src/constants/enum.ts +46 -20
- package/src/constants/index.ts +0 -1
- package/src/constants/poolAddress.ts +252 -66
- package/src/constants/pyth.ts +2 -0
- package/src/constants/queryKeys.ts +7 -9
- package/src/constants/testAddress.ts +24 -0
- package/src/index.ts +0 -1
- package/src/models/scallop.ts +9 -13
- package/src/models/scallopAddress.ts +2 -9
- package/src/models/scallopBuilder.ts +62 -8
- package/src/models/scallopCache.ts +236 -82
- package/src/models/scallopClient.ts +4 -6
- package/src/models/scallopIndexer.ts +1 -5
- package/src/models/scallopQuery.ts +62 -25
- package/src/models/scallopUtils.ts +9 -13
- package/src/queries/borrowIncentiveQuery.ts +6 -13
- package/src/queries/coreQuery.ts +88 -54
- package/src/queries/loyaltyProgramQuery.ts +1 -3
- package/src/queries/objectsQuery.ts +1 -3
- package/src/queries/poolAddressesQuery.ts +16 -7
- package/src/queries/portfolioQuery.ts +253 -21
- package/src/queries/priceQuery.ts +2 -7
- package/src/queries/sCoinQuery.ts +2 -2
- package/src/queries/spoolQuery.ts +21 -20
- package/src/queries/vescaQuery.ts +3 -7
- package/src/types/builder/core.ts +24 -5
- package/src/types/model.ts +13 -2
- package/src/utils/index.ts +0 -2
- package/src/utils/indexer.ts +3 -1
- package/src/utils/query.ts +2 -2
- package/dist/constants/tokenBucket.d.ts +0 -2
- package/dist/utils/tokenBucket.d.ts +0 -11
- package/src/constants/tokenBucket.ts +0 -2
- package/src/utils/tokenBucket.ts +0 -68
|
@@ -1,10 +1,5 @@
|
|
|
1
|
-
import { SuiKit } from '@scallop-io/sui-kit';
|
|
2
|
-
import {
|
|
3
|
-
ADDRESSES_ID,
|
|
4
|
-
SUPPORT_POOLS,
|
|
5
|
-
SUPPORT_SPOOLS,
|
|
6
|
-
DEFAULT_CACHE_OPTIONS,
|
|
7
|
-
} from '../constants';
|
|
1
|
+
import { SuiKit, SuiObjectArg } from '@scallop-io/sui-kit';
|
|
2
|
+
import { ADDRESSES_ID, SUPPORT_POOLS, SUPPORT_SPOOLS } from '../constants';
|
|
8
3
|
import {
|
|
9
4
|
queryMarket,
|
|
10
5
|
getObligations,
|
|
@@ -25,7 +20,6 @@ import {
|
|
|
25
20
|
getLendings,
|
|
26
21
|
getLending,
|
|
27
22
|
getObligationAccounts,
|
|
28
|
-
getObligationAccount,
|
|
29
23
|
getTotalValueLocked,
|
|
30
24
|
queryVeScaKeyIdFromReferralBindings,
|
|
31
25
|
getBindedObligationId,
|
|
@@ -48,6 +42,7 @@ import {
|
|
|
48
42
|
getAllCoinPrices,
|
|
49
43
|
getAllAddresses,
|
|
50
44
|
isIsolatedAsset,
|
|
45
|
+
getUserPortfolio,
|
|
51
46
|
} from '../queries';
|
|
52
47
|
import {
|
|
53
48
|
ScallopQueryParams,
|
|
@@ -64,6 +59,7 @@ import {
|
|
|
64
59
|
MarketPool,
|
|
65
60
|
CoinPrices,
|
|
66
61
|
MarketPools,
|
|
62
|
+
MarketCollaterals,
|
|
67
63
|
} from '../types';
|
|
68
64
|
import { ScallopAddress } from './scallopAddress';
|
|
69
65
|
import { ScallopUtils } from './scallopUtils';
|
|
@@ -73,6 +69,7 @@ import { SuiObjectData } from '@mysten/sui/client';
|
|
|
73
69
|
import { normalizeSuiAddress } from '@mysten/sui/utils';
|
|
74
70
|
import { withIndexerFallback } from 'src/utils/indexer';
|
|
75
71
|
import { newSuiKit } from './suiKit';
|
|
72
|
+
import { SuiObjectRef } from '@mysten/sui/client';
|
|
76
73
|
/**
|
|
77
74
|
* @description
|
|
78
75
|
* It provides methods for getting on-chain data from the Scallop contract.
|
|
@@ -112,11 +109,9 @@ export class ScallopQuery {
|
|
|
112
109
|
this.address = instance.utils.address;
|
|
113
110
|
this.cache = this.address.cache;
|
|
114
111
|
} else {
|
|
115
|
-
this.cache = new ScallopCache(
|
|
116
|
-
this.suiKit,
|
|
117
|
-
|
|
118
|
-
DEFAULT_CACHE_OPTIONS
|
|
119
|
-
);
|
|
112
|
+
this.cache = new ScallopCache(this.params, {
|
|
113
|
+
suiKit: this.suiKit,
|
|
114
|
+
});
|
|
120
115
|
this.address = new ScallopAddress(
|
|
121
116
|
{
|
|
122
117
|
id: params?.addressesId ?? ADDRESSES_ID,
|
|
@@ -299,7 +294,7 @@ export class ScallopQuery {
|
|
|
299
294
|
* @param obligationId - The obligation id.
|
|
300
295
|
* @return Obligation data.
|
|
301
296
|
*/
|
|
302
|
-
public async queryObligation(obligationId: string) {
|
|
297
|
+
public async queryObligation(obligationId: string | SuiObjectArg) {
|
|
303
298
|
return queryObligation(this, obligationId);
|
|
304
299
|
}
|
|
305
300
|
|
|
@@ -565,7 +560,7 @@ export class ScallopQuery {
|
|
|
565
560
|
* @return Borrow incentive accounts data.
|
|
566
561
|
*/
|
|
567
562
|
public async getBorrowIncentiveAccounts(
|
|
568
|
-
obligationId: string,
|
|
563
|
+
obligationId: string | SuiObjectRef,
|
|
569
564
|
coinNames?: SupportBorrowIncentiveCoins[]
|
|
570
565
|
) {
|
|
571
566
|
return await queryBorrowIncentiveAccounts(this, obligationId, coinNames);
|
|
@@ -582,9 +577,20 @@ export class ScallopQuery {
|
|
|
582
577
|
public async getLendings(
|
|
583
578
|
poolCoinNames?: SupportPoolCoins[],
|
|
584
579
|
ownerAddress: string = this.walletAddress,
|
|
585
|
-
args?: {
|
|
580
|
+
args?: {
|
|
581
|
+
indexer?: boolean;
|
|
582
|
+
marketPools?: MarketPools;
|
|
583
|
+
coinPrices?: CoinPrices;
|
|
584
|
+
}
|
|
586
585
|
) {
|
|
587
|
-
return await getLendings(
|
|
586
|
+
return await getLendings(
|
|
587
|
+
this,
|
|
588
|
+
poolCoinNames,
|
|
589
|
+
ownerAddress,
|
|
590
|
+
args?.marketPools,
|
|
591
|
+
args?.coinPrices,
|
|
592
|
+
args?.indexer
|
|
593
|
+
);
|
|
588
594
|
}
|
|
589
595
|
|
|
590
596
|
/**
|
|
@@ -615,9 +621,22 @@ export class ScallopQuery {
|
|
|
615
621
|
*/
|
|
616
622
|
public async getObligationAccounts(
|
|
617
623
|
ownerAddress: string = this.walletAddress,
|
|
618
|
-
args?: {
|
|
624
|
+
args?: {
|
|
625
|
+
indexer?: boolean;
|
|
626
|
+
market?: {
|
|
627
|
+
collaterals: MarketCollaterals;
|
|
628
|
+
pools: MarketPools;
|
|
629
|
+
};
|
|
630
|
+
coinPrices?: CoinPrices;
|
|
631
|
+
}
|
|
619
632
|
) {
|
|
620
|
-
return await getObligationAccounts(
|
|
633
|
+
return await getObligationAccounts(
|
|
634
|
+
this,
|
|
635
|
+
ownerAddress,
|
|
636
|
+
args?.market,
|
|
637
|
+
args?.coinPrices,
|
|
638
|
+
args?.indexer
|
|
639
|
+
);
|
|
621
640
|
}
|
|
622
641
|
|
|
623
642
|
/**
|
|
@@ -636,12 +655,16 @@ export class ScallopQuery {
|
|
|
636
655
|
ownerAddress: string = this.walletAddress,
|
|
637
656
|
args?: { indexer?: boolean }
|
|
638
657
|
) {
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
obligationId
|
|
642
|
-
ownerAddress,
|
|
643
|
-
args?.indexer
|
|
658
|
+
const results = await this.getObligationAccounts(ownerAddress, args);
|
|
659
|
+
return Object.values(results).find(
|
|
660
|
+
(obligation) => obligation?.obligationId === obligationId
|
|
644
661
|
);
|
|
662
|
+
// return await getObligationAccount(
|
|
663
|
+
// this,
|
|
664
|
+
// obligationId,
|
|
665
|
+
// ownerAddress,
|
|
666
|
+
// args?.indexer
|
|
667
|
+
// );
|
|
645
668
|
}
|
|
646
669
|
|
|
647
670
|
/**
|
|
@@ -840,10 +863,24 @@ export class ScallopQuery {
|
|
|
840
863
|
}
|
|
841
864
|
|
|
842
865
|
/**
|
|
843
|
-
* Query all address (lending pool, collateral pool, borrow dynamics, interest models) of all pool
|
|
866
|
+
* Query all address (lending pool, collateral pool, borrow dynamics, interest models, etc.) of all pool
|
|
844
867
|
* @returns
|
|
845
868
|
*/
|
|
846
869
|
public async getPoolAddresses() {
|
|
847
870
|
return getAllAddresses(this);
|
|
848
871
|
}
|
|
872
|
+
|
|
873
|
+
/**
|
|
874
|
+
* Get user portfolio
|
|
875
|
+
*/
|
|
876
|
+
public async getUserPortfolio(args?: {
|
|
877
|
+
walletAddress?: string;
|
|
878
|
+
indexer?: boolean;
|
|
879
|
+
}) {
|
|
880
|
+
return getUserPortfolio(
|
|
881
|
+
this,
|
|
882
|
+
args?.walletAddress ?? this.walletAddress,
|
|
883
|
+
args?.indexer ?? false
|
|
884
|
+
);
|
|
885
|
+
}
|
|
849
886
|
}
|
|
@@ -33,7 +33,6 @@ import {
|
|
|
33
33
|
} from '../utils';
|
|
34
34
|
import { PYTH_ENDPOINTS, PYTH_FEED_IDS } from 'src/constants/pyth';
|
|
35
35
|
import { ScallopCache } from './scallopCache';
|
|
36
|
-
import { DEFAULT_CACHE_OPTIONS } from 'src/constants/cache';
|
|
37
36
|
import type {
|
|
38
37
|
ScallopUtilsParams,
|
|
39
38
|
SupportCoins,
|
|
@@ -49,7 +48,7 @@ import type {
|
|
|
49
48
|
PoolAddressInfo,
|
|
50
49
|
} from '../types';
|
|
51
50
|
import { queryKeys } from 'src/constants';
|
|
52
|
-
import type { SuiObjectArg,
|
|
51
|
+
import type { SuiObjectArg, SuiTxBlock } from '@scallop-io/sui-kit';
|
|
53
52
|
import { newSuiKit } from './suiKit';
|
|
54
53
|
|
|
55
54
|
/**
|
|
@@ -81,21 +80,18 @@ export class ScallopUtils {
|
|
|
81
80
|
pythEndpoints: params.pythEndpoints ?? PYTH_ENDPOINTS['mainnet'],
|
|
82
81
|
...params,
|
|
83
82
|
};
|
|
83
|
+
this.walletAddress =
|
|
84
|
+
params.walletAddress ?? instance?.suiKit?.currentAddress() ?? '';
|
|
84
85
|
this.suiKit =
|
|
85
|
-
instance?.suiKit ?? instance?.address?.cache.
|
|
86
|
-
|
|
87
|
-
this.walletAddress = params.walletAddress ?? this.suiKit.currentAddress();
|
|
86
|
+
instance?.suiKit ?? instance?.address?.cache.suiKit ?? newSuiKit(params);
|
|
88
87
|
|
|
89
88
|
if (instance?.address) {
|
|
90
89
|
this.address = instance.address;
|
|
91
90
|
this.cache = this.address.cache;
|
|
92
|
-
this.suiKit = this.address.cache._suiKit;
|
|
93
91
|
} else {
|
|
94
|
-
this.cache = new ScallopCache(
|
|
95
|
-
this.suiKit,
|
|
96
|
-
|
|
97
|
-
DEFAULT_CACHE_OPTIONS
|
|
98
|
-
);
|
|
92
|
+
this.cache = new ScallopCache(this.params, {
|
|
93
|
+
suiKit: this.suiKit,
|
|
94
|
+
});
|
|
99
95
|
this.address =
|
|
100
96
|
instance?.address ??
|
|
101
97
|
new ScallopAddress(
|
|
@@ -450,7 +446,7 @@ export class ScallopUtils {
|
|
|
450
446
|
coinType: string = SUI_TYPE_ARG,
|
|
451
447
|
ownerAddress?: string
|
|
452
448
|
) {
|
|
453
|
-
ownerAddress = ownerAddress ?? this.
|
|
449
|
+
ownerAddress = ownerAddress ?? this.walletAddress;
|
|
454
450
|
const coins = await this.suiKit.suiInteractor.selectCoins(
|
|
455
451
|
ownerAddress,
|
|
456
452
|
amount,
|
|
@@ -468,7 +464,7 @@ export class ScallopUtils {
|
|
|
468
464
|
*/
|
|
469
465
|
public async mergeSimilarCoins(
|
|
470
466
|
txBlock: SuiTxBlock,
|
|
471
|
-
dest:
|
|
467
|
+
dest: SuiObjectArg,
|
|
472
468
|
coinType: string,
|
|
473
469
|
sender: string = this.walletAddress
|
|
474
470
|
): Promise<void> {
|
|
@@ -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
|
]
|
|
@@ -245,12 +246,8 @@ export const getBindedObligationId = async (
|
|
|
245
246
|
const veScaObjId = address.get('vesca.object');
|
|
246
247
|
|
|
247
248
|
// get incentive pools
|
|
248
|
-
const incentivePoolsResponse =
|
|
249
|
-
incentivePoolsId
|
|
250
|
-
{
|
|
251
|
-
showContent: true,
|
|
252
|
-
}
|
|
253
|
-
);
|
|
249
|
+
const incentivePoolsResponse =
|
|
250
|
+
await address.cache.queryGetObject(incentivePoolsId);
|
|
254
251
|
|
|
255
252
|
if (incentivePoolsResponse?.data?.content?.dataType !== 'moveObject')
|
|
256
253
|
return null;
|
|
@@ -293,12 +290,8 @@ export const getBindedVeScaKey = async (
|
|
|
293
290
|
const corePkg = address.get('core.object');
|
|
294
291
|
|
|
295
292
|
// get IncentiveAccounts object
|
|
296
|
-
const incentiveAccountsObject =
|
|
297
|
-
incentiveAccountsId
|
|
298
|
-
{
|
|
299
|
-
showContent: true,
|
|
300
|
-
}
|
|
301
|
-
);
|
|
293
|
+
const incentiveAccountsObject =
|
|
294
|
+
await address.cache.queryGetObject(incentiveAccountsId);
|
|
302
295
|
if (incentiveAccountsObject?.data?.content?.dataType !== 'moveObject')
|
|
303
296
|
return null;
|
|
304
297
|
const incentiveAccountsTableId = (
|
package/src/queries/coreQuery.ts
CHANGED
|
@@ -13,7 +13,11 @@ import {
|
|
|
13
13
|
calculateMarketCollateralData,
|
|
14
14
|
parseObjectAs,
|
|
15
15
|
} from '../utils';
|
|
16
|
-
import type {
|
|
16
|
+
import type {
|
|
17
|
+
SuiObjectResponse,
|
|
18
|
+
SuiObjectData,
|
|
19
|
+
SuiParsedData,
|
|
20
|
+
} from '@mysten/sui/client';
|
|
17
21
|
import type { SuiObjectArg } from '@scallop-io/sui-kit';
|
|
18
22
|
import type { ScallopAddress, ScallopCache, ScallopQuery } from '../models';
|
|
19
23
|
import {
|
|
@@ -288,33 +292,65 @@ const queryRequiredMarketObjects = async (
|
|
|
288
292
|
// Map the results back to poolCoinNames
|
|
289
293
|
const mapObjects = (
|
|
290
294
|
tasks: { poolCoinName: string; [key: string]: string | undefined }[],
|
|
291
|
-
fetchedObjects: SuiObjectData[]
|
|
295
|
+
fetchedObjects: SuiObjectData[],
|
|
296
|
+
keyValue: string
|
|
292
297
|
) => {
|
|
293
298
|
const resultMap: Record<string, SuiObjectData> = {};
|
|
294
|
-
|
|
299
|
+
const fetchedObjectMap = fetchedObjects.reduce(
|
|
300
|
+
(acc, obj) => {
|
|
301
|
+
acc[obj.objectId] = obj;
|
|
302
|
+
return acc;
|
|
303
|
+
},
|
|
304
|
+
{} as Record<string, SuiObjectData>
|
|
305
|
+
);
|
|
295
306
|
|
|
296
307
|
for (const task of tasks) {
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
resultMap[task.poolCoinName] = fetchedObjects[fetchedIndex];
|
|
300
|
-
fetchedIndex++;
|
|
308
|
+
if (task[keyValue]) {
|
|
309
|
+
resultMap[task.poolCoinName] = fetchedObjectMap[task[keyValue]];
|
|
301
310
|
}
|
|
302
311
|
}
|
|
303
312
|
return resultMap;
|
|
304
313
|
};
|
|
305
314
|
|
|
306
|
-
const balanceSheetMap = mapObjects(
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
const
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
315
|
+
const balanceSheetMap = mapObjects(
|
|
316
|
+
tasks,
|
|
317
|
+
balanceSheetObjects,
|
|
318
|
+
'balanceSheet'
|
|
319
|
+
);
|
|
320
|
+
const collateralStatMap = mapObjects(
|
|
321
|
+
tasks,
|
|
322
|
+
collateralStatObjects,
|
|
323
|
+
'collateralStat'
|
|
324
|
+
);
|
|
325
|
+
const borrowDynamicMap = mapObjects(
|
|
326
|
+
tasks,
|
|
327
|
+
borrowDynamicObjects,
|
|
328
|
+
'borrowDynamic'
|
|
329
|
+
);
|
|
330
|
+
const interestModelMap = mapObjects(
|
|
331
|
+
tasks,
|
|
332
|
+
interestModelObjects,
|
|
333
|
+
'interestModel'
|
|
334
|
+
);
|
|
335
|
+
const riskModelMap = mapObjects(tasks, riskModelObjects, 'riskModel');
|
|
336
|
+
const borrowFeeMap = mapObjects(tasks, borrowFeeObjects, 'borrowFeeKey');
|
|
337
|
+
const supplyLimitMap = mapObjects(
|
|
338
|
+
tasks,
|
|
339
|
+
supplyLimitObjects,
|
|
340
|
+
'supplyLimitKey'
|
|
341
|
+
);
|
|
342
|
+
const borrowLimitMap = mapObjects(
|
|
343
|
+
tasks,
|
|
344
|
+
borrowLimitObjects,
|
|
345
|
+
'borrowLimitKey'
|
|
346
|
+
);
|
|
347
|
+
const isolatedAssetMap = mapObjects(
|
|
348
|
+
tasks,
|
|
349
|
+
isolatedAssetObjects,
|
|
350
|
+
'isolatedAssetKey'
|
|
351
|
+
);
|
|
316
352
|
// Construct the final requiredObjects result
|
|
317
|
-
|
|
353
|
+
const result = poolCoinNames.reduce(
|
|
318
354
|
(acc, name) => {
|
|
319
355
|
acc[name] = {
|
|
320
356
|
balanceSheet: balanceSheetMap[name],
|
|
@@ -344,6 +380,8 @@ const queryRequiredMarketObjects = async (
|
|
|
344
380
|
}
|
|
345
381
|
>
|
|
346
382
|
);
|
|
383
|
+
|
|
384
|
+
return result;
|
|
347
385
|
};
|
|
348
386
|
|
|
349
387
|
/**
|
|
@@ -683,9 +721,7 @@ export const getMarketCollaterals = async (
|
|
|
683
721
|
return marketCollaterals;
|
|
684
722
|
}
|
|
685
723
|
|
|
686
|
-
const marketObjectResponse = await query.cache.queryGetObject(marketId
|
|
687
|
-
showContent: true,
|
|
688
|
-
});
|
|
724
|
+
const marketObjectResponse = await query.cache.queryGetObject(marketId);
|
|
689
725
|
await Promise.allSettled(
|
|
690
726
|
collateralCoinNames.map(async (collateralCoinName) => {
|
|
691
727
|
const marketCollateral = await getMarketCollateral(
|
|
@@ -743,12 +779,7 @@ export const getMarketCollateral = async (
|
|
|
743
779
|
|
|
744
780
|
const marketId = query.address.get('core.market');
|
|
745
781
|
marketObject =
|
|
746
|
-
marketObject ||
|
|
747
|
-
(
|
|
748
|
-
await query.cache.queryGetObject(marketId, {
|
|
749
|
-
showContent: true,
|
|
750
|
-
})
|
|
751
|
-
)?.data;
|
|
782
|
+
marketObject || (await query.cache.queryGetObject(marketId))?.data;
|
|
752
783
|
|
|
753
784
|
if (!(marketObject && marketObject.content?.dataType === 'moveObject'))
|
|
754
785
|
throw new Error(`Failed to fetch marketObject`);
|
|
@@ -902,14 +933,29 @@ export const getObligations = async (
|
|
|
902
933
|
const keyObjects = keyObjectsResponse.filter((ref) => !!ref.data);
|
|
903
934
|
|
|
904
935
|
const obligations: Obligation[] = [];
|
|
936
|
+
// fetch all obligations with multi get objects
|
|
937
|
+
const obligationsObjects = await queryMultipleObjects(
|
|
938
|
+
address.cache,
|
|
939
|
+
keyObjects
|
|
940
|
+
.map((ref) => ref.data?.content)
|
|
941
|
+
.filter(
|
|
942
|
+
(content): content is SuiParsedData & { dataType: 'moveObject' } =>
|
|
943
|
+
content?.dataType === 'moveObject'
|
|
944
|
+
)
|
|
945
|
+
.map((content) => (content.fields as any).ownership.fields.of)
|
|
946
|
+
);
|
|
947
|
+
|
|
905
948
|
await Promise.allSettled(
|
|
906
|
-
keyObjects.map(async ({ data }) => {
|
|
949
|
+
keyObjects.map(async ({ data }, idx) => {
|
|
907
950
|
const keyId = data?.objectId;
|
|
908
951
|
const content = data?.content;
|
|
909
952
|
if (keyId && content && 'fields' in content) {
|
|
910
953
|
const fields = content.fields as any;
|
|
911
954
|
const obligationId = String(fields.ownership.fields.of);
|
|
912
|
-
const locked = await getObligationLocked(
|
|
955
|
+
const locked = await getObligationLocked(
|
|
956
|
+
address.cache,
|
|
957
|
+
obligationsObjects[idx]
|
|
958
|
+
);
|
|
913
959
|
obligations.push({ id: obligationId, keyId, locked });
|
|
914
960
|
}
|
|
915
961
|
})
|
|
@@ -929,23 +975,17 @@ export const getObligationLocked = async (
|
|
|
929
975
|
cache: ScallopCache,
|
|
930
976
|
obligation: string | SuiObjectData
|
|
931
977
|
) => {
|
|
932
|
-
const
|
|
978
|
+
const obligationObjectData =
|
|
933
979
|
typeof obligation === 'string'
|
|
934
|
-
? (
|
|
935
|
-
await cache.queryGetObject(obligation, {
|
|
936
|
-
showContent: true,
|
|
937
|
-
})
|
|
938
|
-
)?.data
|
|
980
|
+
? (await cache.queryGetObject(obligation))?.data
|
|
939
981
|
: obligation;
|
|
940
982
|
let obligationLocked = false;
|
|
941
983
|
if (
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
'lock_key' in
|
|
984
|
+
obligationObjectData &&
|
|
985
|
+
obligationObjectData?.content?.dataType === 'moveObject' &&
|
|
986
|
+
'lock_key' in obligationObjectData.content.fields
|
|
945
987
|
) {
|
|
946
|
-
obligationLocked = Boolean(
|
|
947
|
-
obligationObjectResponse.content.fields.lock_key
|
|
948
|
-
);
|
|
988
|
+
obligationLocked = Boolean(obligationObjectData.content.fields.lock_key);
|
|
949
989
|
}
|
|
950
990
|
|
|
951
991
|
return obligationLocked;
|
|
@@ -1025,11 +1065,11 @@ export const getCoinAmount = async (
|
|
|
1025
1065
|
) => {
|
|
1026
1066
|
const owner = ownerAddress ?? query.suiKit.currentAddress();
|
|
1027
1067
|
const coinType = query.utils.parseCoinType(assetCoinName);
|
|
1028
|
-
const
|
|
1068
|
+
const coinBalance = await query.cache.queryGetCoinBalance({
|
|
1029
1069
|
owner,
|
|
1030
1070
|
coinType: coinType,
|
|
1031
1071
|
});
|
|
1032
|
-
return BigNumber(
|
|
1072
|
+
return BigNumber(coinBalance?.totalBalance ?? '0').toNumber();
|
|
1033
1073
|
};
|
|
1034
1074
|
|
|
1035
1075
|
/**
|
|
@@ -1082,11 +1122,11 @@ export const getMarketCoinAmount = async (
|
|
|
1082
1122
|
) => {
|
|
1083
1123
|
const owner = ownerAddress ?? query.suiKit.currentAddress();
|
|
1084
1124
|
const marketCoinType = query.utils.parseMarketCoinType(marketCoinName);
|
|
1085
|
-
const
|
|
1125
|
+
const coinBalance = await query.cache.queryGetCoinBalance({
|
|
1086
1126
|
owner,
|
|
1087
1127
|
coinType: marketCoinType,
|
|
1088
1128
|
});
|
|
1089
|
-
return BigNumber(
|
|
1129
|
+
return BigNumber(coinBalance?.totalBalance ?? '0').toNumber();
|
|
1090
1130
|
};
|
|
1091
1131
|
|
|
1092
1132
|
/**
|
|
@@ -1125,16 +1165,12 @@ export const getFlashLoanFees = async (
|
|
|
1125
1165
|
})
|
|
1126
1166
|
.filter((t) => !!t) as string[];
|
|
1127
1167
|
|
|
1128
|
-
const flashloanFeeObjects = await query.cache.queryGetObjects(objIds
|
|
1129
|
-
showContent: true,
|
|
1130
|
-
});
|
|
1168
|
+
const flashloanFeeObjects = await query.cache.queryGetObjects(objIds);
|
|
1131
1169
|
|
|
1132
1170
|
if (missingAssets.length > 0) {
|
|
1133
1171
|
// get market object
|
|
1134
1172
|
const marketObjectId = query.address.get('core.market');
|
|
1135
|
-
const marketObjectRes = await query.cache.queryGetObject(marketObjectId
|
|
1136
|
-
showContent: true,
|
|
1137
|
-
});
|
|
1173
|
+
const marketObjectRes = await query.cache.queryGetObject(marketObjectId);
|
|
1138
1174
|
if (marketObjectRes?.data?.content?.dataType !== 'moveObject')
|
|
1139
1175
|
throw new Error('Failed to get market object');
|
|
1140
1176
|
|
|
@@ -1161,9 +1197,7 @@ export const getFlashLoanFees = async (
|
|
|
1161
1197
|
.map((field) => field.objectId) ?? [];
|
|
1162
1198
|
|
|
1163
1199
|
flashloanFeeObjects.push(
|
|
1164
|
-
...(await query.cache.queryGetObjects(dynamicFieldObjectIds
|
|
1165
|
-
showContent: true,
|
|
1166
|
-
}))
|
|
1200
|
+
...(await query.cache.queryGetObjects(dynamicFieldObjectIds))
|
|
1167
1201
|
);
|
|
1168
1202
|
}
|
|
1169
1203
|
|
|
@@ -36,9 +36,7 @@ export const getLoyaltyProgramInformations = async (
|
|
|
36
36
|
const rewardPool = query.address.get('loyaltyProgram.rewardPool');
|
|
37
37
|
|
|
38
38
|
// get fields from rewardPool object
|
|
39
|
-
const rewardPoolObject = await query.cache.queryGetObject(rewardPool
|
|
40
|
-
showContent: true,
|
|
41
|
-
});
|
|
39
|
+
const rewardPoolObject = await query.cache.queryGetObject(rewardPool);
|
|
42
40
|
|
|
43
41
|
if (rewardPoolObject?.data?.content?.dataType !== 'moveObject') return null;
|
|
44
42
|
const rewardPoolFields = rewardPoolObject.data.content.fields;
|
|
@@ -1,18 +1,16 @@
|
|
|
1
|
-
import { SuiObjectDataOptions } from '@mysten/sui/dist/cjs/client';
|
|
2
1
|
import { ScallopCache } from 'src/models/scallopCache';
|
|
3
2
|
import { partitionArray } from 'src/utils';
|
|
4
3
|
|
|
5
4
|
export const queryMultipleObjects = async (
|
|
6
5
|
cache: ScallopCache,
|
|
7
6
|
objectIds: string[],
|
|
8
|
-
options?: SuiObjectDataOptions,
|
|
9
7
|
partitionSize = 50
|
|
10
8
|
) => {
|
|
11
9
|
const objectIdsPartition = partitionArray(objectIds, partitionSize);
|
|
12
10
|
|
|
13
11
|
const objects = [];
|
|
14
12
|
for (const objectIds of objectIdsPartition) {
|
|
15
|
-
const result = await cache.queryGetObjects(objectIds
|
|
13
|
+
const result = await cache.queryGetObjects(objectIds);
|
|
16
14
|
objects.push(...result);
|
|
17
15
|
}
|
|
18
16
|
|
|
@@ -12,6 +12,7 @@ export const getAllAddresses = async (query: ScallopQuery) => {
|
|
|
12
12
|
borrowDynamic?: string;
|
|
13
13
|
spoolReward?: string;
|
|
14
14
|
spool?: string;
|
|
15
|
+
sCoinType?: string;
|
|
15
16
|
sCoinTreasury?: string;
|
|
16
17
|
interestModel?: string;
|
|
17
18
|
riskModel?: string;
|
|
@@ -19,16 +20,15 @@ export const getAllAddresses = async (query: ScallopQuery) => {
|
|
|
19
20
|
supplyLimitKey?: string;
|
|
20
21
|
borrowLimitKey?: string;
|
|
21
22
|
isolatedAssetKey?: string;
|
|
23
|
+
coinMetadataId?: string;
|
|
24
|
+
borrowIncentivePoolId?: string;
|
|
25
|
+
coinType?: string;
|
|
22
26
|
}
|
|
23
27
|
>
|
|
24
28
|
> = {};
|
|
25
29
|
|
|
26
30
|
const marketId = query.address.get('core.market');
|
|
27
|
-
const marketObject = (
|
|
28
|
-
await query.cache.queryGetObject(marketId, {
|
|
29
|
-
showContent: true,
|
|
30
|
-
})
|
|
31
|
-
)?.data;
|
|
31
|
+
const marketObject = (await query.cache.queryGetObject(marketId))?.data;
|
|
32
32
|
|
|
33
33
|
if (!(marketObject && marketObject.content?.dataType === 'moveObject'))
|
|
34
34
|
throw new Error(`Failed to fetch marketObject`);
|
|
@@ -76,7 +76,8 @@ export const getAllAddresses = async (query: ScallopQuery) => {
|
|
|
76
76
|
},
|
|
77
77
|
})
|
|
78
78
|
)?.data?.objectId;
|
|
79
|
-
} catch (
|
|
79
|
+
} catch (e: any) {
|
|
80
|
+
console.error(e.message);
|
|
80
81
|
return undefined;
|
|
81
82
|
}
|
|
82
83
|
};
|
|
@@ -113,10 +114,15 @@ export const getAllAddresses = async (query: ScallopQuery) => {
|
|
|
113
114
|
// @ts-ignore
|
|
114
115
|
`spool.pools.s${coinName}.rewardPoolId`
|
|
115
116
|
);
|
|
117
|
+
// @ts-ignore
|
|
118
|
+
const sCoinType = query.address.get(`scoin.coins.s${coinName}.coinType`);
|
|
116
119
|
const sCoinTreasury = query.address.get(
|
|
117
120
|
// @ts-ignore
|
|
118
121
|
`scoin.coins.s${coinName}.treasury`
|
|
119
122
|
);
|
|
123
|
+
const coinMetadataId = query.address.get(
|
|
124
|
+
`core.coins.${coinName}.metaData`
|
|
125
|
+
);
|
|
120
126
|
results[coinName as SupportPoolCoins] = {
|
|
121
127
|
lendingPoolAddress: addresses[0],
|
|
122
128
|
collateralPoolAddress: addresses[1],
|
|
@@ -130,9 +136,12 @@ export const getAllAddresses = async (query: ScallopQuery) => {
|
|
|
130
136
|
spool,
|
|
131
137
|
spoolReward: rewardPool,
|
|
132
138
|
sCoinTreasury,
|
|
139
|
+
sCoinType,
|
|
140
|
+
coinMetadataId,
|
|
141
|
+
coinType: `0x${coinType}`,
|
|
133
142
|
};
|
|
134
143
|
|
|
135
|
-
await new Promise((resolve) => setTimeout(resolve,
|
|
144
|
+
await new Promise((resolve) => setTimeout(resolve, 500));
|
|
136
145
|
})
|
|
137
146
|
);
|
|
138
147
|
|