@scallop-io/sui-scallop-sdk 1.3.4-alpha.7 → 1.3.4-hotfix
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 +0 -1
- package/dist/constants/index.d.ts +0 -7
- package/dist/constants/pyth.d.ts +0 -2
- package/dist/constants/queryKeys.d.ts +3 -1
- package/dist/constants/tokenBucket.d.ts +1 -1
- package/dist/index.js +2317 -2481
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2316 -2470
- package/dist/index.mjs.map +1 -1
- package/dist/models/scallopPrice.d.ts +0 -0
- package/dist/models/scallopQuery.d.ts +25 -40
- package/dist/models/scallopUtils.d.ts +3 -13
- package/dist/queries/borrowIncentiveQuery.d.ts +2 -2
- package/dist/queries/coreQuery.d.ts +3 -3
- package/dist/queries/index.d.ts +5 -8
- package/dist/queries/{isolatedAssetQuery.d.ts → isolatedAsset.d.ts} +2 -2
- package/dist/queries/sCoinQuery.d.ts +1 -1
- package/dist/queries/spoolQuery.d.ts +3 -3
- package/dist/queries/{supplyLimitQuery.d.ts → supplyLimit.d.ts} +2 -2
- package/dist/types/query/index.d.ts +4 -4
- package/dist/types/utils.d.ts +0 -12
- package/dist/utils/util.d.ts +2 -2
- package/package.json +1 -1
- package/src/builders/loyaltyProgramBuilder.ts +1 -1
- package/src/constants/common.ts +2 -1
- package/src/constants/enum.ts +0 -8
- package/src/constants/index.ts +0 -7
- package/src/constants/pyth.ts +0 -19
- package/src/constants/queryKeys.ts +5 -1
- package/src/constants/tokenBucket.ts +1 -1
- package/src/models/scallop.ts +2 -3
- package/src/models/scallopAddress.ts +2 -2
- package/src/models/scallopBuilder.ts +3 -4
- package/src/models/scallopCache.ts +1 -1
- package/src/models/scallopClient.ts +26 -27
- package/src/models/scallopPrice.ts +0 -0
- package/src/models/scallopQuery.ts +17 -63
- package/src/models/scallopUtils.ts +96 -96
- package/src/queries/borrowIncentiveQuery.ts +13 -6
- package/src/queries/coreQuery.ts +23 -38
- package/src/queries/index.ts +5 -8
- package/src/queries/{isolatedAssetQuery.ts → isolatedAsset.ts} +2 -2
- package/src/queries/loyaltyProgramQuery.ts +1 -1
- package/src/queries/portfolioQuery.ts +34 -55
- package/src/queries/spoolQuery.ts +17 -17
- package/src/queries/{supplyLimitQuery.ts → supplyLimit.ts} +2 -2
- package/src/types/query/index.ts +4 -4
- package/src/types/utils.ts +0 -13
- package/src/utils/tokenBucket.ts +1 -2
- package/src/utils/util.ts +1 -2
- package/dist/constants/coinGecko.d.ts +0 -2
- package/dist/constants/poolAddress.d.ts +0 -5
- package/dist/constants/rpc.d.ts +0 -1
- package/dist/models/suiKit.d.ts +0 -2
- package/src/constants/coinGecko.ts +0 -18
- package/src/constants/poolAddress.ts +0 -94
- package/src/constants/rpc.ts +0 -16
- package/src/models/suiKit.ts +0 -11
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { normalizeStructTag } from '@mysten/sui/utils';
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
SUPPORT_BORROW_INCENTIVE_POOLS,
|
|
4
|
+
SUPPORT_BORROW_INCENTIVE_REWARDS,
|
|
5
|
+
} from '../constants';
|
|
3
6
|
import {
|
|
4
7
|
parseOriginBorrowIncentivePoolData,
|
|
5
8
|
parseOriginBorrowIncentiveAccountData,
|
|
@@ -16,7 +19,6 @@ import type {
|
|
|
16
19
|
BorrowIncentivePoolPoints,
|
|
17
20
|
OptionalKeys,
|
|
18
21
|
BorrowIncentivePool,
|
|
19
|
-
CoinPrices,
|
|
20
22
|
} from '../types';
|
|
21
23
|
import BigNumber from 'bignumber.js';
|
|
22
24
|
|
|
@@ -54,12 +56,17 @@ export const getBorrowIncentivePools = async (
|
|
|
54
56
|
borrowIncentiveCoinNames: SupportBorrowIncentiveCoins[] = [
|
|
55
57
|
...SUPPORT_BORROW_INCENTIVE_POOLS,
|
|
56
58
|
],
|
|
57
|
-
indexer: boolean = false
|
|
58
|
-
coinPrices?: CoinPrices
|
|
59
|
+
indexer: boolean = false
|
|
59
60
|
) => {
|
|
60
61
|
const borrowIncentivePools: BorrowIncentivePools = {};
|
|
61
62
|
|
|
62
|
-
coinPrices =
|
|
63
|
+
const coinPrices =
|
|
64
|
+
(await query.utils.getCoinPrices([
|
|
65
|
+
...new Set([
|
|
66
|
+
...borrowIncentiveCoinNames,
|
|
67
|
+
...SUPPORT_BORROW_INCENTIVE_REWARDS,
|
|
68
|
+
]),
|
|
69
|
+
])) ?? {};
|
|
63
70
|
|
|
64
71
|
if (indexer) {
|
|
65
72
|
const borrowIncentivePoolsIndexer =
|
|
@@ -67,7 +74,7 @@ export const getBorrowIncentivePools = async (
|
|
|
67
74
|
|
|
68
75
|
const updateBorrowIncentivePool = (pool: BorrowIncentivePool) => {
|
|
69
76
|
if (!borrowIncentiveCoinNames.includes(pool.coinName)) return;
|
|
70
|
-
pool.coinPrice = coinPrices[pool.coinName]
|
|
77
|
+
pool.coinPrice = coinPrices[pool.coinName] || pool.coinPrice;
|
|
71
78
|
borrowIncentivePools[pool.coinName] = pool;
|
|
72
79
|
};
|
|
73
80
|
|
package/src/queries/coreQuery.ts
CHANGED
|
@@ -35,10 +35,9 @@ import {
|
|
|
35
35
|
CollateralStat,
|
|
36
36
|
SupportMarketCoins,
|
|
37
37
|
OptionalKeys,
|
|
38
|
-
CoinPrices,
|
|
39
38
|
} from '../types';
|
|
40
39
|
import BigNumber from 'bignumber.js';
|
|
41
|
-
import { getSupplyLimit } from './
|
|
40
|
+
import { getSupplyLimit } from './supplyLimit';
|
|
42
41
|
// import { isIsolatedAsset } from './isolatedAsset';
|
|
43
42
|
|
|
44
43
|
/**
|
|
@@ -53,10 +52,9 @@ import { getSupplyLimit } from './supplyLimitQuery';
|
|
|
53
52
|
*/
|
|
54
53
|
export const queryMarket = async (
|
|
55
54
|
query: ScallopQuery,
|
|
56
|
-
indexer: boolean = false
|
|
57
|
-
coinPrices?: CoinPrices
|
|
55
|
+
indexer: boolean = false
|
|
58
56
|
) => {
|
|
59
|
-
coinPrices =
|
|
57
|
+
const coinPrices = await query.utils.getCoinPrices();
|
|
60
58
|
|
|
61
59
|
const pools: MarketPools = {};
|
|
62
60
|
const collaterals: MarketCollaterals = {};
|
|
@@ -65,13 +63,13 @@ export const queryMarket = async (
|
|
|
65
63
|
const marketIndexer = await query.indexer.getMarket();
|
|
66
64
|
|
|
67
65
|
const updatePools = (item: MarketPool) => {
|
|
68
|
-
item.coinPrice = coinPrices[item.coinName]
|
|
66
|
+
item.coinPrice = coinPrices[item.coinName] || item.coinPrice;
|
|
69
67
|
item.coinWrappedType = query.utils.getCoinWrappedType(item.coinName);
|
|
70
68
|
pools[item.coinName] = item;
|
|
71
69
|
};
|
|
72
70
|
|
|
73
71
|
const updateCollaterals = (item: MarketCollateral) => {
|
|
74
|
-
item.coinPrice = coinPrices[item.coinName]
|
|
72
|
+
item.coinPrice = coinPrices[item.coinName] || item.coinPrice;
|
|
75
73
|
item.coinWrappedType = query.utils.getCoinWrappedType(item.coinName);
|
|
76
74
|
collaterals[item.coinName] = item;
|
|
77
75
|
};
|
|
@@ -232,14 +230,13 @@ export const queryMarket = async (
|
|
|
232
230
|
export const getMarketPools = async (
|
|
233
231
|
query: ScallopQuery,
|
|
234
232
|
poolCoinNames: SupportPoolCoins[] = [...SUPPORT_POOLS],
|
|
235
|
-
indexer: boolean = false
|
|
236
|
-
coinPrices?: CoinPrices
|
|
233
|
+
indexer: boolean = false
|
|
237
234
|
) => {
|
|
238
235
|
const marketId = query.address.get('core.market');
|
|
239
236
|
const marketObjectResponse = await query.cache.queryGetObject(marketId, {
|
|
240
237
|
showContent: true,
|
|
241
238
|
});
|
|
242
|
-
coinPrices = (await query.utils.getCoinPrices(poolCoinNames)) ?? {};
|
|
239
|
+
const coinPrices = (await query.utils.getCoinPrices(poolCoinNames)) ?? {};
|
|
243
240
|
|
|
244
241
|
const marketPools: MarketPools = {};
|
|
245
242
|
|
|
@@ -249,7 +246,7 @@ export const getMarketPools = async (
|
|
|
249
246
|
const updateMarketPool = (marketPool: MarketPool) => {
|
|
250
247
|
if (!poolCoinNames.includes(marketPool.coinName)) return;
|
|
251
248
|
marketPool.coinPrice =
|
|
252
|
-
coinPrices[marketPool.coinName]
|
|
249
|
+
coinPrices[marketPool.coinName] || marketPool.coinPrice;
|
|
253
250
|
marketPool.coinWrappedType = query.utils.getCoinWrappedType(
|
|
254
251
|
marketPool.coinName
|
|
255
252
|
);
|
|
@@ -304,12 +301,12 @@ export const getMarketPool = async (
|
|
|
304
301
|
let borrowFeeRate: { value: string } | undefined;
|
|
305
302
|
|
|
306
303
|
coinPrice =
|
|
307
|
-
coinPrice
|
|
304
|
+
coinPrice ||
|
|
308
305
|
(await query.utils.getCoinPrices([poolCoinName]))?.[poolCoinName];
|
|
309
306
|
|
|
310
307
|
if (indexer) {
|
|
311
308
|
const marketPoolIndexer = await query.indexer.getMarketPool(poolCoinName);
|
|
312
|
-
marketPoolIndexer.coinPrice = coinPrice
|
|
309
|
+
marketPoolIndexer.coinPrice = coinPrice || marketPoolIndexer.coinPrice;
|
|
313
310
|
marketPoolIndexer.coinWrappedType = query.utils.getCoinWrappedType(
|
|
314
311
|
marketPoolIndexer.coinName
|
|
315
312
|
);
|
|
@@ -319,7 +316,7 @@ export const getMarketPool = async (
|
|
|
319
316
|
|
|
320
317
|
const marketId = query.address.get('core.market');
|
|
321
318
|
marketObject =
|
|
322
|
-
marketObject
|
|
319
|
+
marketObject ||
|
|
323
320
|
(
|
|
324
321
|
await query.cache.queryGetObject(marketId, {
|
|
325
322
|
showContent: true,
|
|
@@ -343,10 +340,7 @@ export const getMarketPool = async (
|
|
|
343
340
|
},
|
|
344
341
|
},
|
|
345
342
|
});
|
|
346
|
-
if (!balanceSheetDynamicFieldObjectResponse)
|
|
347
|
-
throw new Error(
|
|
348
|
-
`Failed to fetch balanceSheetDynamicFieldObjectResponse for ${poolCoinName}`
|
|
349
|
-
);
|
|
343
|
+
if (!balanceSheetDynamicFieldObjectResponse) return undefined;
|
|
350
344
|
|
|
351
345
|
const balanceSheetDynamicFieldObject =
|
|
352
346
|
balanceSheetDynamicFieldObjectResponse.data;
|
|
@@ -373,10 +367,7 @@ export const getMarketPool = async (
|
|
|
373
367
|
},
|
|
374
368
|
},
|
|
375
369
|
});
|
|
376
|
-
if (!borrowIndexDynamicFieldObjectResponse)
|
|
377
|
-
throw new Error(
|
|
378
|
-
`Failed to fetch borrowIndexDynamicFieldObjectResponse for ${poolCoinName}`
|
|
379
|
-
);
|
|
370
|
+
if (!borrowIndexDynamicFieldObjectResponse) return undefined;
|
|
380
371
|
|
|
381
372
|
const borrowIndexDynamicFieldObject =
|
|
382
373
|
borrowIndexDynamicFieldObjectResponse.data;
|
|
@@ -404,10 +395,7 @@ export const getMarketPool = async (
|
|
|
404
395
|
},
|
|
405
396
|
});
|
|
406
397
|
|
|
407
|
-
if (!interestModelDynamicFieldObjectResponse)
|
|
408
|
-
throw new Error(
|
|
409
|
-
`Failed to fetch interestModelDynamicFieldObjectResponse for ${poolCoinName}`
|
|
410
|
-
);
|
|
398
|
+
if (!interestModelDynamicFieldObjectResponse) return undefined;
|
|
411
399
|
const interestModelDynamicFieldObject =
|
|
412
400
|
interestModelDynamicFieldObjectResponse.data;
|
|
413
401
|
if (
|
|
@@ -434,10 +422,7 @@ export const getMarketPool = async (
|
|
|
434
422
|
},
|
|
435
423
|
});
|
|
436
424
|
|
|
437
|
-
if (!borrowFeeDynamicFieldObjectResponse)
|
|
438
|
-
throw new Error(
|
|
439
|
-
`Failed to fetch borrowFeeDynamicFieldObjectResponse for ${poolCoinName}`
|
|
440
|
-
);
|
|
425
|
+
if (!borrowFeeDynamicFieldObjectResponse) return undefined;
|
|
441
426
|
const borrowFeeDynamicFieldObject =
|
|
442
427
|
borrowFeeDynamicFieldObjectResponse.data;
|
|
443
428
|
if (
|
|
@@ -470,7 +455,7 @@ export const getMarketPool = async (
|
|
|
470
455
|
reserve: balanceSheet.revenue,
|
|
471
456
|
reserveFactor: interestModel.revenue_factor.fields,
|
|
472
457
|
borrowWeight: interestModel.borrow_weight.fields,
|
|
473
|
-
borrowFeeRate: borrowFeeRate
|
|
458
|
+
borrowFeeRate: borrowFeeRate || { value: '0' },
|
|
474
459
|
baseBorrowRatePerSec: interestModel.base_borrow_rate_per_sec.fields,
|
|
475
460
|
borrowRateOnHighKink: interestModel.borrow_rate_on_high_kink.fields,
|
|
476
461
|
borrowRateOnMidKink: interestModel.borrow_rate_on_mid_kink.fields,
|
|
@@ -546,7 +531,7 @@ export const getMarketCollaterals = async (
|
|
|
546
531
|
const updateMarketCollateral = (marketCollateral: MarketCollateral) => {
|
|
547
532
|
if (!collateralCoinNames.includes(marketCollateral.coinName)) return;
|
|
548
533
|
marketCollateral.coinPrice =
|
|
549
|
-
coinPrices[marketCollateral.coinName]
|
|
534
|
+
coinPrices[marketCollateral.coinName] || marketCollateral.coinPrice;
|
|
550
535
|
marketCollateral.coinWrappedType = query.utils.getCoinWrappedType(
|
|
551
536
|
marketCollateral.coinName
|
|
552
537
|
);
|
|
@@ -605,7 +590,7 @@ export const getMarketCollateral = async (
|
|
|
605
590
|
const marketCollateralIndexer =
|
|
606
591
|
await query.indexer.getMarketCollateral(collateralCoinName);
|
|
607
592
|
marketCollateralIndexer.coinPrice =
|
|
608
|
-
coinPrice
|
|
593
|
+
coinPrice || marketCollateralIndexer.coinPrice;
|
|
609
594
|
marketCollateralIndexer.coinWrappedType = query.utils.getCoinWrappedType(
|
|
610
595
|
marketCollateralIndexer.coinName
|
|
611
596
|
);
|
|
@@ -739,7 +724,7 @@ export const getObligations = async (
|
|
|
739
724
|
ownerAddress: string
|
|
740
725
|
) => {
|
|
741
726
|
const owner = ownerAddress;
|
|
742
|
-
const protocolObjectId = address.get('core.object')
|
|
727
|
+
const protocolObjectId = address.get('core.object') || PROTOCOL_OBJECT_ID;
|
|
743
728
|
const keyObjectsResponse: SuiObjectResponse[] = [];
|
|
744
729
|
let hasNextPage = false;
|
|
745
730
|
let nextCursor: string | null | undefined = null;
|
|
@@ -869,7 +854,7 @@ export const getCoinAmounts = async (
|
|
|
869
854
|
assetCoinNames: SupportAssetCoins[] = [...SUPPORT_POOLS],
|
|
870
855
|
ownerAddress?: string
|
|
871
856
|
) => {
|
|
872
|
-
const owner = ownerAddress
|
|
857
|
+
const owner = ownerAddress || query.suiKit.currentAddress();
|
|
873
858
|
const assetCoins = {} as OptionalKeys<Record<SupportAssetCoins, number>>;
|
|
874
859
|
|
|
875
860
|
await Promise.allSettled(
|
|
@@ -895,7 +880,7 @@ export const getCoinAmount = async (
|
|
|
895
880
|
assetCoinName: SupportAssetCoins,
|
|
896
881
|
ownerAddress?: string
|
|
897
882
|
) => {
|
|
898
|
-
const owner = ownerAddress
|
|
883
|
+
const owner = ownerAddress || query.suiKit.currentAddress();
|
|
899
884
|
const coinType = query.utils.parseCoinType(assetCoinName);
|
|
900
885
|
const amount = await query.cache.queryGetCoinBalance({
|
|
901
886
|
owner,
|
|
@@ -922,7 +907,7 @@ export const getMarketCoinAmounts = async (
|
|
|
922
907
|
[...SUPPORT_POOLS].map((poolCoinName) =>
|
|
923
908
|
query.utils.parseMarketCoinName(poolCoinName)
|
|
924
909
|
);
|
|
925
|
-
const owner = ownerAddress
|
|
910
|
+
const owner = ownerAddress || query.suiKit.currentAddress();
|
|
926
911
|
const marketCoins = {} as OptionalKeys<Record<SupportMarketCoins, number>>;
|
|
927
912
|
|
|
928
913
|
await Promise.allSettled(
|
|
@@ -952,7 +937,7 @@ export const getMarketCoinAmount = async (
|
|
|
952
937
|
marketCoinName: SupportMarketCoins,
|
|
953
938
|
ownerAddress?: string
|
|
954
939
|
) => {
|
|
955
|
-
const owner = ownerAddress
|
|
940
|
+
const owner = ownerAddress || query.suiKit.currentAddress();
|
|
956
941
|
const marketCoinType = query.utils.parseMarketCoinType(marketCoinName);
|
|
957
942
|
const amount = await query.cache.queryGetCoinBalance({
|
|
958
943
|
owner,
|
package/src/queries/index.ts
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
export * from './borrowIncentiveQuery';
|
|
2
1
|
export * from './coreQuery';
|
|
3
|
-
export * from './isolatedAssetQuery';
|
|
4
|
-
export * from './loyaltyProgramQuery';
|
|
5
|
-
export * from './portfolioQuery';
|
|
6
|
-
export * from './priceQuery';
|
|
7
|
-
export * from './referralQuery';
|
|
8
|
-
export * from './sCoinQuery';
|
|
9
2
|
export * from './spoolQuery';
|
|
10
|
-
export * from './
|
|
3
|
+
export * from './borrowIncentiveQuery';
|
|
4
|
+
export * from './priceQuery';
|
|
5
|
+
export * from './portfolioQuery';
|
|
11
6
|
export * from './vescaQuery';
|
|
7
|
+
export * from './referralQuery';
|
|
8
|
+
export * from './loyaltyProgramQuery';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DynamicFieldInfo, DynamicFieldName } from '@mysten/sui/client';
|
|
2
|
-
import { ScallopAddress, ScallopUtils } from '
|
|
3
|
-
import { SupportPoolCoins } from '
|
|
2
|
+
import { ScallopAddress, ScallopUtils } from 'src/models';
|
|
3
|
+
import { SupportPoolCoins } from 'src/types';
|
|
4
4
|
import { z as zod } from 'zod';
|
|
5
5
|
|
|
6
6
|
const isolatedAssetZod = zod.object({
|
|
@@ -53,7 +53,7 @@ export const getLoyaltyProgramInformations = async (
|
|
|
53
53
|
};
|
|
54
54
|
|
|
55
55
|
// query the user pending reward if exist
|
|
56
|
-
veScaKey = veScaKey
|
|
56
|
+
veScaKey = veScaKey || (await query.getVeScas())[0]?.keyObject;
|
|
57
57
|
if (!veScaKey) return result;
|
|
58
58
|
|
|
59
59
|
const userRewardTableId = query.address.get(
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import BigNumber from 'bignumber.js';
|
|
2
2
|
import {
|
|
3
3
|
SUPPORT_BORROW_INCENTIVE_REWARDS,
|
|
4
|
-
SUPPORT_COLLATERALS,
|
|
5
4
|
SUPPORT_POOLS,
|
|
6
5
|
SUPPORT_SPOOLS,
|
|
7
6
|
} from '../constants';
|
|
@@ -50,18 +49,20 @@ export const getLendings = async (
|
|
|
50
49
|
(SUPPORT_SPOOLS as readonly SupportMarketCoins[]).includes(marketCoinName)
|
|
51
50
|
) as SupportStakeMarketCoins[];
|
|
52
51
|
|
|
53
|
-
const
|
|
54
|
-
const marketPools = await query.getMarketPools(poolCoinNames, indexer, {
|
|
55
|
-
coinPrices,
|
|
56
|
-
});
|
|
57
|
-
const spools = await query.getSpools(stakeMarketCoinNames, indexer, {
|
|
52
|
+
const [
|
|
58
53
|
marketPools,
|
|
54
|
+
spools,
|
|
55
|
+
coinAmounts,
|
|
56
|
+
marketCoinAmounts,
|
|
57
|
+
allStakeAccounts,
|
|
59
58
|
coinPrices,
|
|
60
|
-
|
|
61
|
-
|
|
59
|
+
] = await Promise.all([
|
|
60
|
+
query.getMarketPools(poolCoinNames, indexer),
|
|
61
|
+
query.getSpools(stakeMarketCoinNames, indexer),
|
|
62
62
|
query.getCoinAmounts(poolCoinNames, ownerAddress),
|
|
63
63
|
query.getMarketCoinAmounts(marketCoinNames, ownerAddress),
|
|
64
64
|
query.getAllStakeAccounts(ownerAddress),
|
|
65
|
+
query.utils.getCoinPrices(poolCoinNames),
|
|
65
66
|
]);
|
|
66
67
|
|
|
67
68
|
const lendings: Lendings = {};
|
|
@@ -79,7 +80,7 @@ export const getLendings = async (
|
|
|
79
80
|
indexer,
|
|
80
81
|
marketPools?.[poolCoinName],
|
|
81
82
|
stakeMarketCoinName ? spools[stakeMarketCoinName] : undefined,
|
|
82
|
-
stakeMarketCoinName ? allStakeAccounts[stakeMarketCoinName] :
|
|
83
|
+
stakeMarketCoinName ? allStakeAccounts[stakeMarketCoinName] : undefined,
|
|
83
84
|
coinAmounts?.[poolCoinName],
|
|
84
85
|
marketCoinAmounts?.[marketCoinName],
|
|
85
86
|
coinPrices?.[poolCoinName] ?? 0
|
|
@@ -121,37 +122,12 @@ export const getLending = async (
|
|
|
121
122
|
sCoinAmount?: number
|
|
122
123
|
) => {
|
|
123
124
|
const marketCoinName = query.utils.parseMarketCoinName(poolCoinName);
|
|
124
|
-
|
|
125
|
-
coinPrice ??
|
|
126
|
-
(await query.utils.getCoinPrices([poolCoinName]))?.[poolCoinName] ??
|
|
127
|
-
0;
|
|
128
|
-
|
|
129
|
-
marketPool =
|
|
130
|
-
marketPool ??
|
|
131
|
-
(await query.getMarketPool(poolCoinName, indexer, {
|
|
132
|
-
coinPrice,
|
|
133
|
-
}));
|
|
134
|
-
|
|
135
|
-
if (!marketPool)
|
|
136
|
-
throw new Error(`Failed to fetch marketPool for ${poolCoinName}`);
|
|
137
|
-
|
|
125
|
+
marketPool = marketPool || (await query.getMarketPool(poolCoinName, indexer));
|
|
138
126
|
spool =
|
|
139
|
-
|
|
140
|
-
(SUPPORT_SPOOLS as readonly SupportMarketCoins[]).includes(marketCoinName)
|
|
141
|
-
? await query.getSpool(
|
|
142
|
-
marketCoinName as SupportStakeMarketCoins,
|
|
143
|
-
indexer,
|
|
144
|
-
{
|
|
145
|
-
marketPool,
|
|
146
|
-
coinPrices: {
|
|
147
|
-
[poolCoinName]: coinPrice,
|
|
148
|
-
},
|
|
149
|
-
}
|
|
150
|
-
)
|
|
127
|
+
spool ||
|
|
128
|
+
(SUPPORT_SPOOLS as readonly SupportMarketCoins[]).includes(marketCoinName)
|
|
129
|
+
? await query.getSpool(marketCoinName as SupportStakeMarketCoins, indexer)
|
|
151
130
|
: undefined;
|
|
152
|
-
// some pool does not have spool
|
|
153
|
-
// if (!spool) throw new Error(`Failed to fetch spool for ${poolCoinName}`);
|
|
154
|
-
|
|
155
131
|
stakeAccounts =
|
|
156
132
|
stakeAccounts ||
|
|
157
133
|
(SUPPORT_SPOOLS as readonly SupportMarketCoins[]).includes(marketCoinName)
|
|
@@ -167,6 +143,9 @@ export const getLending = async (
|
|
|
167
143
|
(await query.getMarketCoinAmount(marketCoinName, ownerAddress));
|
|
168
144
|
sCoinAmount =
|
|
169
145
|
sCoinAmount || (await query.getSCoinAmount(marketCoinName, ownerAddress));
|
|
146
|
+
coinPrice =
|
|
147
|
+
coinPrice ||
|
|
148
|
+
(await query.utils.getCoinPrices([poolCoinName]))?.[poolCoinName];
|
|
170
149
|
const coinDecimal = query.utils.getCoinDecimal(poolCoinName);
|
|
171
150
|
|
|
172
151
|
// Handle staked scoin
|
|
@@ -310,12 +289,10 @@ export const getObligationAccounts = async (
|
|
|
310
289
|
ownerAddress?: string,
|
|
311
290
|
indexer: boolean = false
|
|
312
291
|
) => {
|
|
292
|
+
const market = await query.queryMarket(indexer);
|
|
313
293
|
const coinPrices = await query.utils.getCoinPrices();
|
|
314
|
-
const
|
|
315
|
-
const
|
|
316
|
-
query.getCoinAmounts(undefined, ownerAddress),
|
|
317
|
-
query.getObligations(ownerAddress),
|
|
318
|
-
]);
|
|
294
|
+
const coinAmounts = await query.getCoinAmounts(undefined, ownerAddress);
|
|
295
|
+
const obligations = await query.getObligations(ownerAddress);
|
|
319
296
|
|
|
320
297
|
const obligationAccounts: ObligationAccounts = {};
|
|
321
298
|
await Promise.allSettled(
|
|
@@ -352,25 +329,27 @@ export const getObligationAccount = async (
|
|
|
352
329
|
coinPrices?: CoinPrices,
|
|
353
330
|
coinAmounts?: CoinAmounts
|
|
354
331
|
) => {
|
|
332
|
+
market = market || (await query.queryMarket(indexer));
|
|
355
333
|
const collateralAssetCoinNames: SupportCollateralCoins[] = [
|
|
356
|
-
...
|
|
334
|
+
...new Set([
|
|
335
|
+
...Object.values(market.collaterals).map(
|
|
336
|
+
(collateral) => collateral.coinName
|
|
337
|
+
),
|
|
338
|
+
]),
|
|
357
339
|
];
|
|
340
|
+
const obligationQuery = await query.queryObligation(obligationId);
|
|
341
|
+
const borrowIncentivePools = await query.getBorrowIncentivePools(
|
|
342
|
+
undefined,
|
|
343
|
+
indexer
|
|
344
|
+
);
|
|
345
|
+
const borrowIncentiveAccounts =
|
|
346
|
+
await query.getBorrowIncentiveAccounts(obligationId);
|
|
358
347
|
coinPrices =
|
|
359
|
-
coinPrices
|
|
360
|
-
market = market ?? (await query.queryMarket(indexer, { coinPrices }));
|
|
348
|
+
coinPrices || (await query.utils.getCoinPrices(collateralAssetCoinNames));
|
|
361
349
|
coinAmounts =
|
|
362
350
|
coinAmounts ||
|
|
363
351
|
(await query.getCoinAmounts(collateralAssetCoinNames, ownerAddress));
|
|
364
352
|
|
|
365
|
-
const [obligationQuery, borrowIncentivePools, borrowIncentiveAccounts] =
|
|
366
|
-
await Promise.all([
|
|
367
|
-
query.queryObligation(obligationId),
|
|
368
|
-
query.getBorrowIncentivePools(undefined, indexer, {
|
|
369
|
-
coinPrices,
|
|
370
|
-
}),
|
|
371
|
-
query.getBorrowIncentiveAccounts(obligationId),
|
|
372
|
-
]);
|
|
373
|
-
|
|
374
353
|
const collaterals: ObligationAccount['collaterals'] = {};
|
|
375
354
|
const debts: ObligationAccount['debts'] = {};
|
|
376
355
|
const borrowIncentives: ObligationAccount['borrowIncentives'] = {};
|
|
@@ -19,7 +19,6 @@ import type {
|
|
|
19
19
|
SupportStakeMarketCoins,
|
|
20
20
|
SupportStakeCoins,
|
|
21
21
|
CoinPrices,
|
|
22
|
-
MarketPools,
|
|
23
22
|
} from '../types';
|
|
24
23
|
|
|
25
24
|
/**
|
|
@@ -33,20 +32,22 @@ import type {
|
|
|
33
32
|
export const getSpools = async (
|
|
34
33
|
query: ScallopQuery,
|
|
35
34
|
stakeMarketCoinNames: SupportStakeMarketCoins[] = [...SUPPORT_SPOOLS],
|
|
36
|
-
indexer: boolean = false
|
|
37
|
-
marketPools?: MarketPools,
|
|
38
|
-
coinPrices?: CoinPrices
|
|
35
|
+
indexer: boolean = false
|
|
39
36
|
) => {
|
|
40
37
|
const stakeCoinNames = stakeMarketCoinNames.map((stakeMarketCoinName) =>
|
|
41
38
|
query.utils.parseCoinName<SupportStakeCoins>(stakeMarketCoinName)
|
|
42
39
|
);
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
40
|
+
const rewardCoinNames = stakeMarketCoinNames.map((stakeMarketCoinName) => {
|
|
41
|
+
const rewardCoinName =
|
|
42
|
+
query.utils.getSpoolRewardCoinName(stakeMarketCoinName);
|
|
43
|
+
return rewardCoinName;
|
|
44
|
+
});
|
|
45
|
+
const coinPrices =
|
|
46
|
+
(await query.utils.getCoinPrices([
|
|
47
|
+
...new Set([...stakeCoinNames, ...rewardCoinNames]),
|
|
48
|
+
])) ?? {};
|
|
49
49
|
|
|
50
|
+
const marketPools = await query.getMarketPools(stakeCoinNames, indexer);
|
|
50
51
|
const spools: Spools = {};
|
|
51
52
|
|
|
52
53
|
if (indexer) {
|
|
@@ -60,13 +61,12 @@ export const getSpools = async (
|
|
|
60
61
|
spool.marketCoinName
|
|
61
62
|
);
|
|
62
63
|
const marketPool = marketPools[coinName];
|
|
63
|
-
spool.coinPrice = coinPrices[coinName]
|
|
64
|
-
spool.marketCoinPrice =
|
|
65
|
-
|
|
66
|
-
(marketPool ? marketPool.conversionRate : 0)
|
|
67
|
-
: spool.marketCoinPrice;
|
|
64
|
+
spool.coinPrice = coinPrices[coinName] || spool.coinPrice;
|
|
65
|
+
spool.marketCoinPrice =
|
|
66
|
+
(coinPrices[coinName] ?? 0) *
|
|
67
|
+
(marketPool ? marketPool.conversionRate : 0) || spool.marketCoinPrice;
|
|
68
68
|
spool.rewardCoinPrice =
|
|
69
|
-
coinPrices[rewardCoinName]
|
|
69
|
+
coinPrices[rewardCoinName] || spool.rewardCoinPrice;
|
|
70
70
|
spools[spool.marketCoinName] = spool;
|
|
71
71
|
};
|
|
72
72
|
Object.values(spoolsIndexer).forEach(updateSpools);
|
|
@@ -114,7 +114,7 @@ export const getSpool = async (
|
|
|
114
114
|
const coinName = query.utils.parseCoinName<SupportStakeCoins>(marketCoinName);
|
|
115
115
|
marketPool = marketPool || (await query.getMarketPool(coinName, indexer));
|
|
116
116
|
if (!marketPool) {
|
|
117
|
-
throw new Error(
|
|
117
|
+
throw new Error('Fail to fetch marketPool');
|
|
118
118
|
}
|
|
119
119
|
|
|
120
120
|
const poolId = query.address.get(`spool.pools.${marketCoinName}.id`);
|
package/src/types/query/index.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export type * from './borrowIncentive';
|
|
2
1
|
export type * from './core';
|
|
3
|
-
export type * from './loyaltyProgram';
|
|
4
|
-
export type * from './portfolio';
|
|
5
|
-
export type * from './sCoin';
|
|
6
2
|
export type * from './spool';
|
|
3
|
+
export type * from './borrowIncentive';
|
|
4
|
+
export type * from './portfolio';
|
|
7
5
|
export type * from './vesca';
|
|
6
|
+
export type * from './loyaltyProgram';
|
|
7
|
+
export type * from './sCoin';
|
package/src/types/utils.ts
CHANGED
|
@@ -13,16 +13,3 @@ export type PriceMap = Map<
|
|
|
13
13
|
publishTime: number;
|
|
14
14
|
}
|
|
15
15
|
>;
|
|
16
|
-
|
|
17
|
-
export type PoolAddressInfo = {
|
|
18
|
-
name: string;
|
|
19
|
-
coingeckoId: string;
|
|
20
|
-
decimal: number;
|
|
21
|
-
pythFeedId: string;
|
|
22
|
-
lendingPoolAddress: string;
|
|
23
|
-
collateralPoolAddress: string;
|
|
24
|
-
sCoinAddress: string | undefined;
|
|
25
|
-
marketCoinAddress: string;
|
|
26
|
-
coinAddress: string;
|
|
27
|
-
sCoinName: string | undefined;
|
|
28
|
-
};
|
package/src/utils/tokenBucket.ts
CHANGED
|
@@ -38,7 +38,7 @@ const callWithRateLimit = async <T>(
|
|
|
38
38
|
tokenBucket: TokenBucket,
|
|
39
39
|
fn: () => Promise<T>,
|
|
40
40
|
retryDelayInMs = DEFAULT_INTERVAL_IN_MS,
|
|
41
|
-
maxRetries =
|
|
41
|
+
maxRetries = 15,
|
|
42
42
|
backoffFactor = 1.25 // The factor by which to increase the delay
|
|
43
43
|
): Promise<T | null> => {
|
|
44
44
|
let retries = 0;
|
|
@@ -65,7 +65,6 @@ const callWithRateLimit = async <T>(
|
|
|
65
65
|
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
66
66
|
return tryRequest();
|
|
67
67
|
} else {
|
|
68
|
-
// console.error(error);
|
|
69
68
|
console.error('An error occurred:', error.message);
|
|
70
69
|
return null;
|
|
71
70
|
}
|
package/src/utils/util.ts
CHANGED
|
@@ -14,7 +14,6 @@ import type {
|
|
|
14
14
|
SupportAssetCoins,
|
|
15
15
|
SupportCoins,
|
|
16
16
|
SupportMarketCoins,
|
|
17
|
-
SupportSCoin,
|
|
18
17
|
SupportSuiBridgeCoins,
|
|
19
18
|
SupportWormholeCoins,
|
|
20
19
|
} from '../types';
|
|
@@ -31,7 +30,7 @@ const COIN_SET = Array.from(
|
|
|
31
30
|
|
|
32
31
|
export const isMarketCoin = (
|
|
33
32
|
coinName: SupportCoins
|
|
34
|
-
): coinName is SupportMarketCoins
|
|
33
|
+
): coinName is SupportMarketCoins => {
|
|
35
34
|
const assetCoinName = coinName.slice(1).toLowerCase() as SupportAssetCoins;
|
|
36
35
|
return (
|
|
37
36
|
coinName.charAt(0).toLowerCase() === 's' && COIN_SET.includes(assetCoinName)
|
package/dist/constants/rpc.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const RPC_PROVIDERS: string[];
|
package/dist/models/suiKit.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { SupportPoolCoins } from 'src/types/constant/common';
|
|
2
|
-
|
|
3
|
-
export const COIN_GECKGO_IDS: Record<SupportPoolCoins, string> = {
|
|
4
|
-
usdc: 'usdc-coin',
|
|
5
|
-
sbeth: 'ethereum',
|
|
6
|
-
weth: 'ethereum',
|
|
7
|
-
wbtc: 'bitcoin',
|
|
8
|
-
wusdc: 'usdc-coin',
|
|
9
|
-
wusdt: 'tether',
|
|
10
|
-
sui: 'sui',
|
|
11
|
-
wapt: 'aptos',
|
|
12
|
-
wsol: 'solana',
|
|
13
|
-
cetus: 'cetus-protocol',
|
|
14
|
-
afsui: 'sui',
|
|
15
|
-
hasui: 'sui',
|
|
16
|
-
vsui: 'sui',
|
|
17
|
-
sca: 'scallop-2',
|
|
18
|
-
};
|