@scallop-io/sui-scallop-sdk 2.0.13-merge-split-ve-sca-alpha.5 → 2.1.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/index.d.mts +622 -697
- package/dist/index.d.ts +622 -697
- package/dist/index.js +32 -33
- package/dist/index.mjs +10 -10
- package/package.json +8 -18
- package/src/builders/borrowIncentiveBuilder.ts +9 -21
- package/src/builders/coreBuilder.ts +2 -2
- package/src/builders/index.ts +2 -2
- package/src/builders/oracles/index.ts +2 -3
- package/src/builders/oracles/pyth.ts +2 -2
- package/src/builders/spoolBuilder.ts +2 -2
- package/src/builders/vescaBuilder.ts +14 -132
- package/src/constants/queryKeys.ts +29 -54
- package/src/constants/testAddress.ts +6 -12
- package/src/index.ts +11 -1
- package/src/models/index.ts +11 -9
- package/src/models/interface.ts +36 -0
- package/src/models/scallop.ts +38 -133
- package/src/models/scallopAddress.ts +127 -142
- package/src/models/scallopAxios.ts +185 -0
- package/src/models/scallopBuilder.ts +45 -75
- package/src/models/scallopClient.ts +124 -154
- package/src/models/scallopConstants.ts +248 -323
- package/src/models/scallopIndexer.ts +54 -98
- package/src/models/scallopQuery.ts +145 -190
- package/src/models/scallopQueryClient.ts +29 -0
- package/src/models/scallopSuiKit.ts +432 -0
- package/src/models/scallopUtils.ts +260 -164
- package/src/queries/borrowIncentiveQuery.ts +28 -16
- package/src/queries/borrowLimitQuery.ts +1 -1
- package/src/queries/coreQuery.ts +148 -107
- package/src/queries/flashloanFeeQuery.ts +12 -6
- package/src/queries/index.ts +0 -1
- package/src/queries/isolatedAssetQuery.ts +3 -3
- package/src/queries/loyaltyProgramQuery.ts +10 -8
- package/src/queries/ownerQuery.ts +32 -0
- package/src/queries/portfolioQuery.ts +4 -5
- package/src/queries/priceQuery.ts +14 -8
- package/src/queries/referralQuery.ts +9 -3
- package/src/queries/sCoinQuery.ts +4 -4
- package/src/queries/spoolQuery.ts +11 -11
- package/src/queries/supplyLimitQuery.ts +1 -1
- package/src/queries/switchboardQuery.ts +1 -1
- package/src/queries/vescaQuery.ts +31 -27
- package/src/queries/xOracleQuery.ts +13 -8
- package/src/types/address.ts +0 -3
- package/src/types/builder/core.ts +1 -1
- package/src/types/builder/vesca.ts +10 -20
- package/src/types/constant/queryKeys.ts +48 -0
- package/src/types/index.ts +0 -1
- package/src/utils/builder.ts +1 -1
- package/src/utils/util.ts +1 -33
- package/src/models/scallopCache.ts +0 -428
- package/src/queries/objectsQuery.ts +0 -18
- package/src/types/model.ts +0 -117
package/src/queries/coreQuery.ts
CHANGED
|
@@ -5,14 +5,14 @@ import {
|
|
|
5
5
|
parseOriginMarketCollateralData,
|
|
6
6
|
calculateMarketCollateralData,
|
|
7
7
|
parseObjectAs,
|
|
8
|
-
} from '
|
|
8
|
+
} from '../utils';
|
|
9
9
|
import type {
|
|
10
10
|
SuiObjectResponse,
|
|
11
11
|
SuiObjectData,
|
|
12
12
|
SuiParsedData,
|
|
13
13
|
} from '@mysten/sui/client';
|
|
14
14
|
import type { SuiObjectArg } from '@scallop-io/sui-kit';
|
|
15
|
-
import type { ScallopAddress, ScallopCache, ScallopQuery } from '
|
|
15
|
+
// import type { ScallopAddress, ScallopCache, ScallopQuery } from '../models';
|
|
16
16
|
import {
|
|
17
17
|
Market,
|
|
18
18
|
MarketPools,
|
|
@@ -32,14 +32,19 @@ import {
|
|
|
32
32
|
BorrowFee,
|
|
33
33
|
BorrowDynamic,
|
|
34
34
|
OriginMarketCollateralData,
|
|
35
|
-
} from '
|
|
35
|
+
} from '../types';
|
|
36
36
|
import BigNumber from 'bignumber.js';
|
|
37
37
|
import { getSupplyLimit } from './supplyLimitQuery';
|
|
38
38
|
import { isIsolatedAsset } from './isolatedAssetQuery';
|
|
39
39
|
import { getBorrowLimit } from './borrowLimitQuery';
|
|
40
|
-
import { queryMultipleObjects } from './objectsQuery';
|
|
41
|
-
import { ScallopConstants } from 'src/models/scallopConstants';
|
|
42
40
|
import { queryFlashLoanFees } from './flashloanFeeQuery';
|
|
41
|
+
import {
|
|
42
|
+
ScallopSuiKit,
|
|
43
|
+
ScallopQuery,
|
|
44
|
+
ScallopUtils,
|
|
45
|
+
ScallopIndexer,
|
|
46
|
+
ScallopAddress,
|
|
47
|
+
} from 'src/models';
|
|
43
48
|
|
|
44
49
|
/**
|
|
45
50
|
* Query market data.
|
|
@@ -54,27 +59,33 @@ import { queryFlashLoanFees } from './flashloanFeeQuery';
|
|
|
54
59
|
* @return Market data.
|
|
55
60
|
*/
|
|
56
61
|
export const queryMarket = async (
|
|
57
|
-
|
|
58
|
-
|
|
62
|
+
{
|
|
63
|
+
utils,
|
|
64
|
+
indexer,
|
|
65
|
+
}: {
|
|
66
|
+
utils: ScallopUtils;
|
|
67
|
+
indexer: ScallopIndexer;
|
|
68
|
+
},
|
|
69
|
+
useIndexer: boolean = false,
|
|
59
70
|
coinPrices?: CoinPrices
|
|
60
71
|
) => {
|
|
61
|
-
coinPrices = coinPrices ?? (await
|
|
72
|
+
coinPrices = coinPrices ?? (await utils.getCoinPrices()) ?? {};
|
|
62
73
|
|
|
63
74
|
const pools: MarketPools = {};
|
|
64
75
|
const collaterals: MarketCollaterals = {};
|
|
65
76
|
|
|
66
|
-
if (
|
|
67
|
-
const marketIndexer = await
|
|
77
|
+
if (useIndexer) {
|
|
78
|
+
const marketIndexer = await indexer.getMarket();
|
|
68
79
|
|
|
69
80
|
const updatePools = (item: MarketPool) => {
|
|
70
81
|
item.coinPrice = coinPrices[item.coinName] ?? item.coinPrice;
|
|
71
|
-
item.coinWrappedType =
|
|
82
|
+
item.coinWrappedType = utils.getCoinWrappedType(item.coinName);
|
|
72
83
|
pools[item.coinName] = item;
|
|
73
84
|
};
|
|
74
85
|
|
|
75
86
|
const updateCollaterals = (item: MarketCollateral) => {
|
|
76
87
|
item.coinPrice = coinPrices[item.coinName] ?? item.coinPrice;
|
|
77
|
-
item.coinWrappedType =
|
|
88
|
+
item.coinWrappedType = utils.getCoinWrappedType(item.coinName);
|
|
78
89
|
collaterals[item.coinName] = item;
|
|
79
90
|
};
|
|
80
91
|
|
|
@@ -91,23 +102,26 @@ export const queryMarket = async (
|
|
|
91
102
|
};
|
|
92
103
|
}
|
|
93
104
|
|
|
94
|
-
const packageId =
|
|
95
|
-
const marketId =
|
|
105
|
+
const packageId = utils.address.get('core.packages.query.id');
|
|
106
|
+
const marketId = utils.address.get('core.market');
|
|
96
107
|
const queryTarget = `${packageId}::market_query::market_data`;
|
|
97
108
|
const args = [marketId];
|
|
98
109
|
|
|
99
|
-
const queryResult = await
|
|
110
|
+
const queryResult = await utils.scallopSuiKit.queryInspectTxn({
|
|
111
|
+
queryTarget,
|
|
112
|
+
args,
|
|
113
|
+
});
|
|
100
114
|
const marketData = queryResult?.events[0]?.parsedJson as
|
|
101
115
|
| MarketQueryInterface
|
|
102
116
|
| undefined;
|
|
103
117
|
|
|
104
118
|
for (const pool of marketData?.pools ?? []) {
|
|
105
119
|
const coinType = normalizeStructTag(pool.type.name);
|
|
106
|
-
const poolCoinName =
|
|
120
|
+
const poolCoinName = utils.parseCoinNameFromType(coinType);
|
|
107
121
|
const coinPrice = coinPrices[poolCoinName] ?? 0;
|
|
108
122
|
|
|
109
123
|
// Filter pools not yet supported by the SDK.
|
|
110
|
-
if (!
|
|
124
|
+
if (!utils.constants.whitelist.lending.has(poolCoinName)) {
|
|
111
125
|
continue;
|
|
112
126
|
}
|
|
113
127
|
|
|
@@ -131,26 +145,24 @@ export const queryMarket = async (
|
|
|
131
145
|
highKink: pool.highKink,
|
|
132
146
|
midKink: pool.midKink,
|
|
133
147
|
minBorrowAmount: pool.minBorrowAmount,
|
|
134
|
-
isIsolated: await isIsolatedAsset(
|
|
135
|
-
supplyLimit: (await getSupplyLimit(
|
|
136
|
-
borrowLimit: (await getBorrowLimit(
|
|
148
|
+
isIsolated: await isIsolatedAsset(utils, poolCoinName),
|
|
149
|
+
supplyLimit: (await getSupplyLimit(utils, poolCoinName)) ?? '0',
|
|
150
|
+
borrowLimit: (await getBorrowLimit(utils, poolCoinName)) ?? '0',
|
|
137
151
|
});
|
|
138
152
|
|
|
139
153
|
const calculatedMarketPoolData = calculateMarketPoolData(
|
|
140
|
-
|
|
154
|
+
utils,
|
|
141
155
|
parsedMarketPoolData
|
|
142
156
|
);
|
|
143
157
|
|
|
144
158
|
pools[poolCoinName] = {
|
|
145
159
|
coinName: poolCoinName,
|
|
146
|
-
symbol:
|
|
160
|
+
symbol: utils.parseSymbol(poolCoinName),
|
|
147
161
|
coinType: coinType,
|
|
148
|
-
marketCoinType:
|
|
162
|
+
marketCoinType: utils.parseMarketCoinType(poolCoinName),
|
|
149
163
|
sCoinType:
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
) ?? '',
|
|
153
|
-
coinWrappedType: query.utils.getCoinWrappedType(poolCoinName),
|
|
164
|
+
utils.parseSCoinType(utils.parseMarketCoinName(poolCoinName)) ?? '',
|
|
165
|
+
coinWrappedType: utils.getCoinWrappedType(poolCoinName),
|
|
154
166
|
coinPrice: coinPrice,
|
|
155
167
|
highKink: parsedMarketPoolData.highKink,
|
|
156
168
|
midKink: parsedMarketPoolData.midKink,
|
|
@@ -165,11 +177,11 @@ export const queryMarket = async (
|
|
|
165
177
|
|
|
166
178
|
for (const collateral of marketData?.collaterals ?? []) {
|
|
167
179
|
const coinType = normalizeStructTag(collateral.type.name);
|
|
168
|
-
const collateralCoinName =
|
|
180
|
+
const collateralCoinName = utils.parseCoinNameFromType(coinType);
|
|
169
181
|
const coinPrice = coinPrices[collateralCoinName] ?? 0;
|
|
170
182
|
|
|
171
183
|
// Filter collaterals not yet supported by the SDK.
|
|
172
|
-
if (!
|
|
184
|
+
if (!utils.constants.whitelist.collateral.has(collateralCoinName)) {
|
|
173
185
|
continue;
|
|
174
186
|
}
|
|
175
187
|
|
|
@@ -182,20 +194,20 @@ export const queryMarket = async (
|
|
|
182
194
|
liquidationReserveFactor: collateral.liquidationReserveFactor,
|
|
183
195
|
maxCollateralAmount: collateral.maxCollateralAmount,
|
|
184
196
|
totalCollateralAmount: collateral.totalCollateralAmount,
|
|
185
|
-
isIsolated: await isIsolatedAsset(
|
|
197
|
+
isIsolated: await isIsolatedAsset(utils, collateralCoinName),
|
|
186
198
|
});
|
|
187
199
|
|
|
188
200
|
const calculatedMarketCollateralData = calculateMarketCollateralData(
|
|
189
|
-
|
|
201
|
+
utils,
|
|
190
202
|
parsedMarketCollateralData
|
|
191
203
|
);
|
|
192
204
|
|
|
193
205
|
collaterals[collateralCoinName] = {
|
|
194
206
|
coinName: collateralCoinName,
|
|
195
|
-
symbol:
|
|
207
|
+
symbol: utils.parseSymbol(collateralCoinName),
|
|
196
208
|
coinType: coinType,
|
|
197
|
-
marketCoinType:
|
|
198
|
-
coinWrappedType:
|
|
209
|
+
marketCoinType: utils.parseMarketCoinType(collateralCoinName),
|
|
210
|
+
coinWrappedType: utils.getCoinWrappedType(collateralCoinName),
|
|
199
211
|
coinPrice: coinPrice,
|
|
200
212
|
collateralFactor: parsedMarketCollateralData.collateralFactor,
|
|
201
213
|
liquidationFactor: parsedMarketCollateralData.liquidationFactor,
|
|
@@ -216,7 +228,13 @@ export const queryMarket = async (
|
|
|
216
228
|
};
|
|
217
229
|
|
|
218
230
|
const queryRequiredMarketObjects = async (
|
|
219
|
-
|
|
231
|
+
{
|
|
232
|
+
utils,
|
|
233
|
+
scallopSuiKit,
|
|
234
|
+
}: {
|
|
235
|
+
utils: ScallopUtils;
|
|
236
|
+
scallopSuiKit: ScallopSuiKit;
|
|
237
|
+
},
|
|
220
238
|
poolCoinNames: string[]
|
|
221
239
|
) => {
|
|
222
240
|
// Phase 1: Single-pass data preparation with proper typing
|
|
@@ -246,7 +264,7 @@ const queryRequiredMarketObjects = async (
|
|
|
246
264
|
|
|
247
265
|
// Single iteration to collect all keys and map tasks
|
|
248
266
|
for (const poolCoinName of poolCoinNames) {
|
|
249
|
-
const poolData =
|
|
267
|
+
const poolData = utils.constants.poolAddresses[poolCoinName];
|
|
250
268
|
const task: KeyType = {
|
|
251
269
|
balanceSheet: poolData?.lendingPoolAddress,
|
|
252
270
|
collateralStat: poolData?.collateralPoolAddress,
|
|
@@ -269,15 +287,18 @@ const queryRequiredMarketObjects = async (
|
|
|
269
287
|
}
|
|
270
288
|
|
|
271
289
|
// Phase 2: Parallel queries with pre-collected keys
|
|
290
|
+
const options = {
|
|
291
|
+
showContent: true,
|
|
292
|
+
};
|
|
272
293
|
const queryResults = await Promise.all([
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
294
|
+
scallopSuiKit.queryGetObjects(keyCollections.balanceSheet, options),
|
|
295
|
+
scallopSuiKit.queryGetObjects(keyCollections.collateralStat, options),
|
|
296
|
+
scallopSuiKit.queryGetObjects(keyCollections.borrowDynamic, options),
|
|
297
|
+
scallopSuiKit.queryGetObjects(keyCollections.interestModel, options),
|
|
298
|
+
scallopSuiKit.queryGetObjects(keyCollections.riskModel, options),
|
|
299
|
+
scallopSuiKit.queryGetObjects(keyCollections.borrowFeeKey, options),
|
|
300
|
+
scallopSuiKit.queryGetObjects(keyCollections.supplyLimitKey, options),
|
|
301
|
+
scallopSuiKit.queryGetObjects(keyCollections.borrowLimitKey, options),
|
|
281
302
|
]);
|
|
282
303
|
|
|
283
304
|
// Phase 3: Single-pass result mapping
|
|
@@ -328,7 +349,7 @@ const queryRequiredMarketObjects = async (
|
|
|
328
349
|
borrowLimitKey: task.borrowLimitKey
|
|
329
350
|
? resultMaps.borrowLimitKey.get(task.borrowLimitKey)
|
|
330
351
|
: undefined,
|
|
331
|
-
isolatedAssetKey:
|
|
352
|
+
isolatedAssetKey: utils.constants.poolAddresses[poolCoinName]?.isIsolated,
|
|
332
353
|
};
|
|
333
354
|
}
|
|
334
355
|
|
|
@@ -647,21 +668,29 @@ export const getMarketPool = async (
|
|
|
647
668
|
* @return Market collaterals data.
|
|
648
669
|
*/
|
|
649
670
|
export const getMarketCollaterals = async (
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
671
|
+
{
|
|
672
|
+
utils,
|
|
673
|
+
indexer,
|
|
674
|
+
scallopSuiKit,
|
|
675
|
+
}: {
|
|
676
|
+
utils: ScallopUtils;
|
|
677
|
+
indexer: ScallopIndexer;
|
|
678
|
+
scallopSuiKit: ScallopSuiKit;
|
|
679
|
+
},
|
|
680
|
+
collateralCoinNames: string[] = [...utils.constants.whitelist.collateral],
|
|
681
|
+
useIndexer: boolean = false
|
|
653
682
|
) => {
|
|
654
|
-
const marketId =
|
|
655
|
-
const coinPrices = (await
|
|
683
|
+
const marketId = utils.address.get('core.market');
|
|
684
|
+
const coinPrices = (await utils.getCoinPrices()) ?? {};
|
|
656
685
|
const marketCollaterals: MarketCollaterals = {};
|
|
657
686
|
|
|
658
|
-
if (
|
|
659
|
-
const marketCollateralsIndexer = await
|
|
687
|
+
if (useIndexer) {
|
|
688
|
+
const marketCollateralsIndexer = await indexer.getMarketCollaterals();
|
|
660
689
|
const updateMarketCollateral = (marketCollateral: MarketCollateral) => {
|
|
661
690
|
if (!collateralCoinNames.includes(marketCollateral.coinName)) return;
|
|
662
691
|
marketCollateral.coinPrice =
|
|
663
692
|
coinPrices[marketCollateral.coinName] ?? marketCollateral.coinPrice;
|
|
664
|
-
marketCollateral.coinWrappedType =
|
|
693
|
+
marketCollateral.coinWrappedType = utils.getCoinWrappedType(
|
|
665
694
|
marketCollateral.coinName
|
|
666
695
|
);
|
|
667
696
|
marketCollaterals[marketCollateral.coinName] = marketCollateral;
|
|
@@ -672,13 +701,17 @@ export const getMarketCollaterals = async (
|
|
|
672
701
|
return marketCollaterals;
|
|
673
702
|
}
|
|
674
703
|
|
|
675
|
-
const marketObjectResponse = await
|
|
704
|
+
const marketObjectResponse = await scallopSuiKit.queryGetObject(marketId);
|
|
676
705
|
await Promise.allSettled(
|
|
677
706
|
collateralCoinNames.map(async (collateralCoinName) => {
|
|
678
707
|
const marketCollateral = await getMarketCollateral(
|
|
679
|
-
|
|
708
|
+
{
|
|
709
|
+
utils,
|
|
710
|
+
indexer,
|
|
711
|
+
scallopSuiKit,
|
|
712
|
+
},
|
|
680
713
|
collateralCoinName,
|
|
681
|
-
|
|
714
|
+
useIndexer,
|
|
682
715
|
marketObjectResponse?.data,
|
|
683
716
|
coinPrices?.[collateralCoinName]
|
|
684
717
|
);
|
|
@@ -703,21 +736,28 @@ export const getMarketCollaterals = async (
|
|
|
703
736
|
* @returns Market collateral data.
|
|
704
737
|
*/
|
|
705
738
|
export const getMarketCollateral = async (
|
|
706
|
-
|
|
739
|
+
{
|
|
740
|
+
utils,
|
|
741
|
+
indexer,
|
|
742
|
+
scallopSuiKit,
|
|
743
|
+
}: {
|
|
744
|
+
utils: ScallopUtils;
|
|
745
|
+
indexer: ScallopIndexer;
|
|
746
|
+
scallopSuiKit: ScallopSuiKit;
|
|
747
|
+
},
|
|
707
748
|
collateralCoinName: string,
|
|
708
|
-
|
|
749
|
+
useIndexer: boolean = false,
|
|
709
750
|
marketObject?: SuiObjectData | null,
|
|
710
751
|
coinPrice?: number
|
|
711
752
|
): Promise<MarketCollateral | undefined> => {
|
|
712
|
-
coinPrice =
|
|
713
|
-
coinPrice ?? (await query.utils.getCoinPrices())?.[collateralCoinName];
|
|
753
|
+
coinPrice = coinPrice ?? (await utils.getCoinPrices())?.[collateralCoinName];
|
|
714
754
|
|
|
715
|
-
if (
|
|
755
|
+
if (useIndexer) {
|
|
716
756
|
const marketCollateralIndexer =
|
|
717
|
-
await
|
|
757
|
+
await indexer.getMarketCollateral(collateralCoinName);
|
|
718
758
|
marketCollateralIndexer.coinPrice =
|
|
719
759
|
coinPrice ?? marketCollateralIndexer.coinPrice;
|
|
720
|
-
marketCollateralIndexer.coinWrappedType =
|
|
760
|
+
marketCollateralIndexer.coinWrappedType = utils.getCoinWrappedType(
|
|
721
761
|
marketCollateralIndexer.coinName
|
|
722
762
|
);
|
|
723
763
|
|
|
@@ -728,20 +768,20 @@ export const getMarketCollateral = async (
|
|
|
728
768
|
// let riskModel: RiskModel | undefined;
|
|
729
769
|
// let collateralStat: CollateralStat | undefined;
|
|
730
770
|
|
|
731
|
-
const marketId =
|
|
771
|
+
const marketId = utils.address.get('core.market');
|
|
732
772
|
marketObject =
|
|
733
|
-
marketObject || (await
|
|
773
|
+
marketObject || (await scallopSuiKit.queryGetObject(marketId))?.data;
|
|
734
774
|
|
|
735
775
|
if (!(marketObject && marketObject.content?.dataType === 'moveObject'))
|
|
736
776
|
throw new Error(`Failed to fetch marketObject`);
|
|
737
777
|
|
|
738
778
|
const fields = marketObject.content.fields as any;
|
|
739
|
-
const coinType =
|
|
779
|
+
const coinType = utils.parseCoinType(collateralCoinName);
|
|
740
780
|
|
|
741
781
|
// Get risk model.
|
|
742
782
|
const riskModelParentId = fields.risk_models.fields.table.fields.id.id;
|
|
743
783
|
const riskModelDynamicFieldObjectResponse =
|
|
744
|
-
await
|
|
784
|
+
await scallopSuiKit.queryGetDynamicFieldObject({
|
|
745
785
|
parentId: riskModelParentId,
|
|
746
786
|
name: {
|
|
747
787
|
type: '0x1::type_name::TypeName',
|
|
@@ -771,7 +811,7 @@ export const getMarketCollateral = async (
|
|
|
771
811
|
const collateralStatParentId =
|
|
772
812
|
fields.collateral_stats.fields.table.fields.id.id;
|
|
773
813
|
const collateralStatDynamicFieldObjectResponse =
|
|
774
|
-
await
|
|
814
|
+
await scallopSuiKit.queryGetDynamicFieldObject({
|
|
775
815
|
parentId: collateralStatParentId,
|
|
776
816
|
name: {
|
|
777
817
|
type: '0x1::type_name::TypeName',
|
|
@@ -808,20 +848,20 @@ export const getMarketCollateral = async (
|
|
|
808
848
|
liquidationReserveFactor: riskModel.liquidation_revenue_factor.fields,
|
|
809
849
|
maxCollateralAmount: riskModel.max_collateral_amount,
|
|
810
850
|
totalCollateralAmount: collateralStat.amount,
|
|
811
|
-
isIsolated: await isIsolatedAsset(
|
|
851
|
+
isIsolated: await isIsolatedAsset(utils, collateralCoinName),
|
|
812
852
|
});
|
|
813
853
|
|
|
814
854
|
const calculatedMarketCollateralData = calculateMarketCollateralData(
|
|
815
|
-
|
|
855
|
+
utils,
|
|
816
856
|
parsedMarketCollateralData
|
|
817
857
|
);
|
|
818
858
|
|
|
819
859
|
return {
|
|
820
860
|
coinName: collateralCoinName,
|
|
821
|
-
symbol:
|
|
822
|
-
coinType:
|
|
823
|
-
marketCoinType:
|
|
824
|
-
coinWrappedType:
|
|
861
|
+
symbol: utils.parseSymbol(collateralCoinName),
|
|
862
|
+
coinType: utils.parseCoinType(collateralCoinName),
|
|
863
|
+
marketCoinType: utils.parseMarketCoinType(collateralCoinName),
|
|
864
|
+
coinWrappedType: utils.getCoinWrappedType(collateralCoinName),
|
|
825
865
|
coinPrice: coinPrice ?? 0,
|
|
826
866
|
collateralFactor: parsedMarketCollateralData.collateralFactor,
|
|
827
867
|
liquidationFactor: parsedMarketCollateralData.liquidationFactor,
|
|
@@ -842,20 +882,20 @@ export const getMarketCollateral = async (
|
|
|
842
882
|
*/
|
|
843
883
|
export const getObligations = async (
|
|
844
884
|
{
|
|
845
|
-
|
|
885
|
+
utils,
|
|
846
886
|
}: {
|
|
847
|
-
|
|
887
|
+
utils: ScallopUtils;
|
|
848
888
|
},
|
|
849
889
|
ownerAddress: string
|
|
850
890
|
) => {
|
|
851
891
|
const owner = ownerAddress;
|
|
852
|
-
const protocolObjectId = constants.protocolObjectId;
|
|
892
|
+
const protocolObjectId = utils.constants.protocolObjectId;
|
|
853
893
|
const keyObjectsResponse: SuiObjectResponse[] = [];
|
|
854
894
|
let hasNextPage = false;
|
|
855
895
|
let nextCursor: string | null | undefined = null;
|
|
856
896
|
do {
|
|
857
897
|
const paginatedKeyObjectsResponse =
|
|
858
|
-
await
|
|
898
|
+
await utils.scallopSuiKit.queryGetOwnedObjects({
|
|
859
899
|
owner,
|
|
860
900
|
filter: {
|
|
861
901
|
StructType: `${protocolObjectId}::obligation::ObligationKey`,
|
|
@@ -885,8 +925,7 @@ export const getObligations = async (
|
|
|
885
925
|
|
|
886
926
|
const obligations: Obligation[] = [];
|
|
887
927
|
// fetch all obligations with multi get objects
|
|
888
|
-
const obligationsObjects = await
|
|
889
|
-
constants.cache,
|
|
928
|
+
const obligationsObjects = await utils.scallopSuiKit.queryGetObjects(
|
|
890
929
|
keyObjects
|
|
891
930
|
.map((ref) => ref.data?.content)
|
|
892
931
|
.filter(
|
|
@@ -904,7 +943,7 @@ export const getObligations = async (
|
|
|
904
943
|
const fields = content.fields as any;
|
|
905
944
|
const obligationId = String(fields.ownership.fields.of);
|
|
906
945
|
const locked = await getObligationLocked(
|
|
907
|
-
|
|
946
|
+
utils,
|
|
908
947
|
obligationsObjects[idx]
|
|
909
948
|
);
|
|
910
949
|
obligations.push({ id: obligationId, keyId, locked });
|
|
@@ -923,12 +962,12 @@ export const getObligations = async (
|
|
|
923
962
|
* @return Obligation locked status.
|
|
924
963
|
*/
|
|
925
964
|
export const getObligationLocked = async (
|
|
926
|
-
|
|
965
|
+
{ scallopSuiKit }: { scallopSuiKit: ScallopSuiKit },
|
|
927
966
|
obligation: string | SuiObjectData
|
|
928
967
|
) => {
|
|
929
968
|
const obligationObjectData =
|
|
930
969
|
typeof obligation === 'string'
|
|
931
|
-
? (await
|
|
970
|
+
? (await scallopSuiKit.queryGetObject(obligation))?.data
|
|
932
971
|
: obligation;
|
|
933
972
|
let obligationLocked = false;
|
|
934
973
|
if (
|
|
@@ -955,8 +994,10 @@ export const getObligationLocked = async (
|
|
|
955
994
|
export const queryObligation = async (
|
|
956
995
|
{
|
|
957
996
|
address,
|
|
997
|
+
scallopSuiKit,
|
|
958
998
|
}: {
|
|
959
999
|
address: ScallopAddress;
|
|
1000
|
+
scallopSuiKit: ScallopSuiKit;
|
|
960
1001
|
},
|
|
961
1002
|
obligationId: SuiObjectArg
|
|
962
1003
|
) => {
|
|
@@ -976,7 +1017,7 @@ export const queryObligation = async (
|
|
|
976
1017
|
},
|
|
977
1018
|
];
|
|
978
1019
|
|
|
979
|
-
const queryResult = await
|
|
1020
|
+
const queryResult = await scallopSuiKit.queryInspectTxn(
|
|
980
1021
|
{ queryTarget, args }
|
|
981
1022
|
// txBlock
|
|
982
1023
|
);
|
|
@@ -994,17 +1035,17 @@ export const queryObligation = async (
|
|
|
994
1035
|
* @return All owned coin amounts.
|
|
995
1036
|
*/
|
|
996
1037
|
export const getCoinAmounts = async (
|
|
997
|
-
|
|
998
|
-
assetCoinNames: string[] = [...
|
|
1038
|
+
{ utils }: { utils: ScallopUtils },
|
|
1039
|
+
assetCoinNames: string[] = [...utils.constants.whitelist.lending],
|
|
999
1040
|
ownerAddress?: string
|
|
1000
1041
|
) => {
|
|
1001
|
-
const owner = ownerAddress ??
|
|
1042
|
+
const owner = ownerAddress ?? utils.walletAddress;
|
|
1002
1043
|
const assetCoins = {} as OptionalKeys<Record<string, number>>;
|
|
1003
1044
|
|
|
1004
1045
|
await Promise.allSettled(
|
|
1005
1046
|
assetCoinNames.map(async (assetCoinName) => {
|
|
1006
|
-
const
|
|
1007
|
-
assetCoins[assetCoinName] =
|
|
1047
|
+
const coinAmount = await getCoinAmount({ utils }, assetCoinName, owner);
|
|
1048
|
+
assetCoins[assetCoinName] = coinAmount;
|
|
1008
1049
|
})
|
|
1009
1050
|
);
|
|
1010
1051
|
|
|
@@ -1020,13 +1061,13 @@ export const getCoinAmounts = async (
|
|
|
1020
1061
|
* @return Owned coin amount.
|
|
1021
1062
|
*/
|
|
1022
1063
|
export const getCoinAmount = async (
|
|
1023
|
-
|
|
1064
|
+
{ utils }: { utils: ScallopUtils },
|
|
1024
1065
|
assetCoinName: string,
|
|
1025
1066
|
ownerAddress?: string
|
|
1026
1067
|
) => {
|
|
1027
|
-
const owner = ownerAddress ??
|
|
1028
|
-
const coinType =
|
|
1029
|
-
const coinBalance = await
|
|
1068
|
+
const owner = ownerAddress ?? utils.walletAddress;
|
|
1069
|
+
const coinType = utils.parseCoinType(assetCoinName);
|
|
1070
|
+
const coinBalance = await utils.scallopSuiKit.queryGetCoinBalance({
|
|
1030
1071
|
owner,
|
|
1031
1072
|
coinType: coinType,
|
|
1032
1073
|
});
|
|
@@ -1042,22 +1083,22 @@ export const getCoinAmount = async (
|
|
|
1042
1083
|
* @return All owned market coins amount.
|
|
1043
1084
|
*/
|
|
1044
1085
|
export const getMarketCoinAmounts = async (
|
|
1045
|
-
|
|
1086
|
+
{ utils }: { utils: ScallopUtils },
|
|
1046
1087
|
marketCoinNames?: string[],
|
|
1047
1088
|
ownerAddress?: string
|
|
1048
1089
|
) => {
|
|
1049
1090
|
marketCoinNames =
|
|
1050
1091
|
marketCoinNames ||
|
|
1051
|
-
[...
|
|
1052
|
-
|
|
1092
|
+
[...utils.constants.whitelist.lending].map((poolCoinName) =>
|
|
1093
|
+
utils.parseMarketCoinName(poolCoinName)
|
|
1053
1094
|
);
|
|
1054
|
-
const owner = ownerAddress ??
|
|
1095
|
+
const owner = ownerAddress ?? utils.walletAddress;
|
|
1055
1096
|
const marketCoins = {} as OptionalKeys<Record<string, number>>;
|
|
1056
1097
|
|
|
1057
1098
|
await Promise.allSettled(
|
|
1058
1099
|
marketCoinNames.map(async (marketCoinName) => {
|
|
1059
1100
|
const marketCoin = await getMarketCoinAmount(
|
|
1060
|
-
|
|
1101
|
+
{ utils },
|
|
1061
1102
|
marketCoinName,
|
|
1062
1103
|
owner
|
|
1063
1104
|
);
|
|
@@ -1077,13 +1118,13 @@ export const getMarketCoinAmounts = async (
|
|
|
1077
1118
|
* @return Owned market coin amount.
|
|
1078
1119
|
*/
|
|
1079
1120
|
export const getMarketCoinAmount = async (
|
|
1080
|
-
|
|
1121
|
+
{ utils }: { utils: ScallopUtils },
|
|
1081
1122
|
marketCoinName: string,
|
|
1082
1123
|
ownerAddress?: string
|
|
1083
1124
|
) => {
|
|
1084
|
-
const owner = ownerAddress ??
|
|
1085
|
-
const marketCoinType =
|
|
1086
|
-
const coinBalance = await
|
|
1125
|
+
const owner = ownerAddress ?? utils.walletAddress;
|
|
1126
|
+
const marketCoinType = utils.parseMarketCoinType(marketCoinName);
|
|
1127
|
+
const coinBalance = await utils.scallopSuiKit.queryGetCoinBalance({
|
|
1087
1128
|
owner,
|
|
1088
1129
|
coinType: marketCoinType,
|
|
1089
1130
|
});
|
|
@@ -1098,7 +1139,7 @@ export const getMarketCoinAmount = async (
|
|
|
1098
1139
|
*/
|
|
1099
1140
|
|
|
1100
1141
|
export const getFlashLoanFees = async (
|
|
1101
|
-
|
|
1142
|
+
{ utils }: { utils: ScallopUtils },
|
|
1102
1143
|
assetNames: string[],
|
|
1103
1144
|
feeRate = 1e4
|
|
1104
1145
|
): Promise<Record<string, number>> => {
|
|
@@ -1108,7 +1149,7 @@ export const getFlashLoanFees = async (
|
|
|
1108
1149
|
// create mapping from asset type to asset name
|
|
1109
1150
|
const assetTypeMap = assetNames.reduce(
|
|
1110
1151
|
(prev, curr) => {
|
|
1111
|
-
const assetType =
|
|
1152
|
+
const assetType = utils.parseCoinType(curr).slice(2);
|
|
1112
1153
|
prev[assetType] = curr;
|
|
1113
1154
|
return prev;
|
|
1114
1155
|
},
|
|
@@ -1119,7 +1160,7 @@ export const getFlashLoanFees = async (
|
|
|
1119
1160
|
const objIds = assetNames
|
|
1120
1161
|
.map((assetName) => {
|
|
1121
1162
|
const mappedFlashloanFeeObject =
|
|
1122
|
-
|
|
1163
|
+
utils.constants.poolAddresses[assetName]?.flashloanFeeObject;
|
|
1123
1164
|
if (!mappedFlashloanFeeObject) {
|
|
1124
1165
|
missingAssets.push(assetName);
|
|
1125
1166
|
return null;
|
|
@@ -1129,11 +1170,11 @@ export const getFlashLoanFees = async (
|
|
|
1129
1170
|
})
|
|
1130
1171
|
.filter((t) => !!t) as string[];
|
|
1131
1172
|
|
|
1132
|
-
const flashloanFeeObjects = await
|
|
1173
|
+
const flashloanFeeObjects = await utils.scallopSuiKit.queryGetObjects(objIds);
|
|
1133
1174
|
|
|
1134
1175
|
if (missingAssets.length > 0) {
|
|
1135
1176
|
const missingDatas = await queryFlashLoanFees(
|
|
1136
|
-
|
|
1177
|
+
utils,
|
|
1137
1178
|
missingAssets,
|
|
1138
1179
|
feeRate
|
|
1139
1180
|
);
|
|
@@ -1,18 +1,24 @@
|
|
|
1
1
|
import { SuiObjectData } from '@mysten/sui/client';
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
2
|
+
import { ScallopSuiKit } from 'src/models';
|
|
3
|
+
import ScallopConstants from 'src/models/scallopConstants';
|
|
4
4
|
|
|
5
5
|
const FLASHLOAN_FEES_TABLE_ID =
|
|
6
6
|
'0x00481a93b819d744a7d79ecdc6c62c74f2f7cb4779316c4df640415817ac61bb' as const;
|
|
7
7
|
|
|
8
8
|
export const queryFlashLoanFees = async (
|
|
9
|
-
|
|
9
|
+
{
|
|
10
|
+
constants,
|
|
11
|
+
scallopSuiKit,
|
|
12
|
+
}: {
|
|
13
|
+
constants: ScallopConstants;
|
|
14
|
+
scallopSuiKit: ScallopSuiKit;
|
|
15
|
+
},
|
|
10
16
|
assetNames: string[],
|
|
11
17
|
feeRate: number
|
|
12
18
|
) => {
|
|
13
19
|
const assetNamesSet = new Set(assetNames);
|
|
14
20
|
const assetTypeMap = Object.fromEntries(
|
|
15
|
-
Object.entries(
|
|
21
|
+
Object.entries(constants.coinTypeToCoinNameMap).filter(([_, value]) =>
|
|
16
22
|
assetNamesSet.has(value!)
|
|
17
23
|
)
|
|
18
24
|
);
|
|
@@ -21,7 +27,7 @@ export const queryFlashLoanFees = async (
|
|
|
21
27
|
let nextPage: boolean = false;
|
|
22
28
|
const flashloanFeeObjects: SuiObjectData[] = [];
|
|
23
29
|
do {
|
|
24
|
-
const resp = await
|
|
30
|
+
const resp = await scallopSuiKit.queryGetDynamicFields({
|
|
25
31
|
parentId: FLASHLOAN_FEES_TABLE_ID,
|
|
26
32
|
limit: 10,
|
|
27
33
|
cursor,
|
|
@@ -39,7 +45,7 @@ export const queryFlashLoanFees = async (
|
|
|
39
45
|
.map((field) => field.objectId) ?? [];
|
|
40
46
|
|
|
41
47
|
flashloanFeeObjects.push(
|
|
42
|
-
...(await
|
|
48
|
+
...(await scallopSuiKit.queryGetObjects(dynamicFieldObjectIds))
|
|
43
49
|
);
|
|
44
50
|
nextPage = hasNextPage;
|
|
45
51
|
cursor = nextCursor;
|
package/src/queries/index.ts
CHANGED
|
@@ -53,7 +53,7 @@ export const getIsolatedAssets = async (
|
|
|
53
53
|
};
|
|
54
54
|
|
|
55
55
|
do {
|
|
56
|
-
const response = await query.
|
|
56
|
+
const response = await query.scallopSuiKit.queryGetDynamicFields({
|
|
57
57
|
parentId: marketObject,
|
|
58
58
|
cursor: nextCursor,
|
|
59
59
|
limit: 10,
|
|
@@ -95,7 +95,7 @@ export const isIsolatedAsset = async (
|
|
|
95
95
|
|
|
96
96
|
const marketObject = utils.address.get('core.market');
|
|
97
97
|
// check if the coin type is in the list
|
|
98
|
-
const cachedData = utils.
|
|
98
|
+
const cachedData = utils.queryClient.getQueryData<string[]>([
|
|
99
99
|
'getDynamicFields',
|
|
100
100
|
marketObject,
|
|
101
101
|
]);
|
|
@@ -107,7 +107,7 @@ export const isIsolatedAsset = async (
|
|
|
107
107
|
// fetch dynamic field object
|
|
108
108
|
const coinType = utils.parseCoinType(coinName).slice(2);
|
|
109
109
|
|
|
110
|
-
const object = await utils.
|
|
110
|
+
const object = await utils.scallopSuiKit.queryGetDynamicFieldObject({
|
|
111
111
|
parentId: marketObject,
|
|
112
112
|
name: {
|
|
113
113
|
type: isolatedAssetKeyType,
|